Sto cercando di imparare le funzioni ajax di jQuery. Ho funzionato, ma jQuery non trova elementi nel DOM HTML restituito. Nella stessa cartella di jQuery, eseguire questa pagina:Esempio semplice di jQuery ajax che non trova elementi in HTML restituito
<!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>
che carica la pagina "ajaxtest-load.html":
<!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>
Dà due avvisi. Uno che mostrava il DOM era stato caricato, ma il secondo mostra NULL invece del # wrapper. Che cosa sto facendo di sbagliato?
EDIT: Sto caricando "ajaxtest-load.html" che include l'intera intestazione, incluso jquery di nuovo. È questo il problema?
Forse ripulire il codice principale e pubblicare l'aspetto del codice HTML su 'ajaxtest-load.html' – ScottE
Il secondo blocco html è ajaxtest-load.html. Modificato la descrizione. Mi dispiace per quello – user110218