响应是一个 HTML 文档(来自链接的 href 的请求)
var data = $(response).find('body').html();
alert(data);
// I get a alert with nothing...
完整代码:
$.ajax({
url: $(this).attr('href'),
type: 'GET',
success: function(response){
var data = $(response).find('body').html();
alert(data);
}
});
最佳答案
这样试试:
var $dom = $(document.createElement("html"));
$dom[0].innerHTML = response;
var $body = $dom.find("body");
关于javascript - 无法从 ajax 响应中获取正文元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7001926/