Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use XML data embedded in HTML in javascript (ajax)?
    text
    copied!<p>I am pretty new to HTML and such and I am trying to create a HTML page that is completely 'self-contained' so all the CSS, data and JavaScript that it needs will be embedded in the HTML (I know this will create a very ugly HTML file, but I do not mind) I need to do this because I need to be able to send the HTML file to colleagues so they can open it without having to run a local server and without anything being uploaded on an online server. </p> <p>For now, I've managed to add all the CSS and Javascript, but the Javascript uses ajax to load an external XML file with the data. I cannot seem to get this to work when I embed the XML into the HTML and try to load it through ajax</p> <p>I've embedded the XML data inside the HTML like so:</p> <pre><code>&lt;script id="graphFile" type="text/xmldata"&gt; &lt;gexf&gt; &lt;graph defaultedgetype="directed" mode="static"&gt; &lt;attributes class="node" mode="static"&gt; &lt;attribute id="v_name" title="name" type="string"&gt;&lt;/attribute&gt; &lt;attribute id="indegree" title="In-Degree" type="integer"&gt; &lt;default&gt;0&lt;/default&gt; &lt;/attribute&gt; ...more data... &lt;/graph&gt; &lt;/gexf&gt; &lt;/script&gt; </code></pre> <p>In the javascript the original XML file was parsed like so (which I have taken from the example I am basing my own HTML on):</p> <pre><code>function loadGraph() { $.ajax({ url: "graphFile.xml", dataType: "xml", success: function(data) { ...calculate stuff... } }); } </code></pre> <p>However, I have no idea how I can parse the data from the XML embedded in the HTML so the <code>function(data)</code> will still work</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload