Prosty przykład jQuery ajax nie znajduje elementów w zwróconym HTML
Próbuję nauczyć się funkcji ajax jQuery. Mam to działa, ale jQuery nie znajduje elementów w zwróconym HTML DOM. W tym samym folderze co jquery uruchom tę stronę:
<code><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <title>runthis</title> <script type="text/javascript" language="javascript" src="jquery-1.3.2.min.js"></script> <script tyle="text/javascript"> $(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."); } }); }); }); </script </head> <body> <input type="button" value="load" /> </body> </html> </code>
Która ładuje tę stronę „ajaxtest-load.html”:
<code><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <title>load this</title> </head> <body> <div id="wrapper"> test </div> </body> </html> </code>
Daje dwa alerty. Jeden pokazujący DOM został załadowany, ale drugi pokazuje NULL zamiast #wrapper. Co ja robię źle?
EDIT: Ładuję „ajaxtest-load.html”, który zawiera cały nagłówek, w tym ponownie jquery. Czy to jest ten problem?