Note that there are some explanatory texts on larger screens.

plurals
  1. POread xml file using jquery in an html file
    primarykey
    data
    text
    <p>I am new to jQuery and am trying to read in an xml file. I have created a simple html file as shown below and in the same directory have an xml file called allTasks.xml. I see the alert when the document is loaded and I see the second alert 'Here Now'. However when I try and use the find method I cannot traverse the xml correctly. Is there a good way to test if I am actually loading the xml file at all? Also should this work in a html file or should I be using php?</p> <p>Any help would be greatly received !</p> <pre><code>html &lt;!doctype html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt; &lt;title&gt;Read XML File&lt;/title&gt; &lt;link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css"&gt; &lt;script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ alert('Loaded'); var $myXML; $.get('allTasks.xml', function(data) { $myXML = data; ; }, 'xml'); alert('Here now '); alert($myXML.find("Tasks&gt;Task&gt;TaskId").text()); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div data-role="page" id="page1"&gt; &lt;div data-role="header" class="ui-bar ui-bar-b" style="height:50px;"&gt; &lt;/div&gt; &lt;!-- end of header --&gt; &lt;div data-role="content"&gt; &lt;div id='names'&gt;&lt;/div&gt; &lt;/div&gt; &lt;!-- end of content --&gt; &lt;/div&gt; &lt;!-- end of page div --&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>xml</p> <pre><code>&lt;TaskList&gt; &lt;Tasks&gt; &lt;Task&gt; &lt;TaskId&gt;1&lt;/TaskId&gt; &lt;Name&gt;Name of Task 1&lt;/Name&gt; &lt;/Task&gt; &lt;Task&gt; &lt;TaskId&gt;2&lt;/TaskId&gt; &lt;Name&gt;Name of Task 2&lt;/Name&gt; &lt;/Task&gt; &lt;/Tasks&gt; &lt;/TaskList&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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