Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple jQuery ajax example not finding elements in returned HTML
    primarykey
    data
    text
    <p>I'm trying to learn jQuery's ajax functions. I've got it working, but jQuery doesn't find elements in the returned HTML DOM. In the same folder as jquery, run this page:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"&gt; &lt;head&gt; &lt;title&gt;runthis&lt;/title&gt; &lt;script type="text/javascript" language="javascript" src="jquery-1.3.2.min.js"&gt;&lt;/script&gt; &lt;script tyle="text/javascript"&gt; $(document).ready(function(){ $('input').click(function(){ $.ajax({ type : "GET", url : 'ajaxtest-load.html', dataType : "html", success: function(data) { alert( data ); // shows whole dom alert( $(data).find('#wrapper').html() ); // returns null }, error : function() { alert("Sorry, The requested property could not be found."); } }); }); }); &lt;/script &lt;/head&gt; &lt;body&gt; &lt;input type="button" value="load" /&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Which loads this page "ajaxtest-load.html":</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"&gt; &lt;head&gt; &lt;title&gt;load this&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="wrapper"&gt; test &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>It gives two alerts. One showing the DOM was loaded, but the second shows NULL instead of the #wrapper. What am I doing wrong? </p> <p>EDIT: I'm loading "ajaxtest-load.html" which includes the whole header, including jquery again. Is that the issue?</p>
    singulars
    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.
 

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