Exemplo simples de jQuery ajax não encontrando elementos no HTML retornado
Estou tentando aprender as funções de jjax do ajax. Eu tenho isso funcionando, mas o jQuery não encontra elementos no HTML DOM retornado. Na mesma pasta que jquery, execute esta página:
<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>
Que carrega esta página "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>
Dá dois alertas. Um mostrando o DOM foi carregado, mas o segundo mostra NULL em vez do #wrapper. O que estou fazendo de errado?
EDIT: Estou carregando "ajaxtest-load.html", que inclui todo o cabeçalho, incluindo jquery novamente. Esse é o problema?