Comment puis-je interroger le code HTML renvoyé par AJAX?Requête HTML retournée par AJAX
J'ai essayé
$.post("gethtml.php", { url: $url.val() }, function(data) {
var $html = $(data),
$links = $("link, script, style", $html),
$body = $("body", $html);
$links.each(function() { $(this).addClass("tmp"); });
console.log($html);
console.log($body.html());
});
$html
ressemble [meta, title, script, style#gstyle, script, textarea#csi, div#mngb, iframe, center, script, script]
et $body.html()
null
MISE À JOUR
Une configuration simple à http://jsfiddle.net/uvnrJ/1/
$(function() {
var html = "<!doctype html><html><head><title>title here ... </title></head><body>This is the body</body></html>",
$html = $(html);
console.log($html); // jQuery(title, <TextNode textContent="This is the body">)
console.log($html.find("body")); // jQuery()
console.log($html.find("title")); // jQuery()
console.log($html.filter("title")); // jQuery(title)
});
Indique que jQuery semble avoir des problèmes pour analyser la chaîne HTML?
qu'est-ce que vous essayez de faire? –
Avez-vous essayé '$ body = $ (data) .find ('body');'? –
@expérienceX J'essaie d'obtenir la source HTML d'une autre page Web. –