【发布时间】:2012-08-31 23:18:48
【问题描述】:
我只是在执行一个简单的 ajax 请求来获取文件的内容,但是当我尝试获取实际的 <body> 时,它总是什么都不返回。
jQuery.ajax(location).done(function(response) {
// RETURNS []
console.log(jQuery(response).find('body'));
// <body class="html ...">
// RETURNS []
console.log(jQuery(response).find('.html'));
// When I try to get any other div it just works
// RETURNS THE DIV
console.log(jQuery(response).find('#header'));
})
【问题讨论】:
-
响应包含的实际数据是什么?
-
只是来自网站
<html><head></head><body>...的完整html所以源代码 -
location是否与您的页面在同一个域中? -
是的,为了清楚起见,我正在获取文件的实际内容,.find() 方法无法获取
<body>的内容,我可以但是搜索任何 id 或类。 -
看这里,同样的问题有解决方案:stackoverflow.com/questions/7839889/…