本文介绍了Jquery find不能处理AJAX返回数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
function openFaceBox(path) {
$.ajax({
type: "GET",
url: path,
success: function( data ) {
$.facebox( data ); // data returns html
var tableHeight = $(data).find('table').height();
console.log( tableHeight ); // Output : 0 (Zero)
}
});
}
我的AJAX返回html如下:
My AJAX return html is below :
<div id="holder-1">
<h1>Content 1</h1>
</div>
<div id="holder-2">
<h1>Content 2</h1>
</div>
<div id="holder-3">
<h1>Content 3</h1>
</div>
<table>
<tr>
<td>abcd</td>
<td>Some Text Here Some Text Here Some Text Here Some Text Here
Some Text Here Some Text Here Some Text Here Some Text Here Some Text
Here Some Text Here Some Text Here Some Text Here Some Text Here Some
Text Here Some Text Here Some Text Here Some Text Here Some Text Here
Some Text Here Some Text Here Some Text Here Some Text Here Some Text
Here</td>
</tr>
</table>
我无法弄清楚为什么 .find()
无法正常工作。基本上我想找到桌子高度。任何混淆请告诉我。
I can not figure out why .find()
is not working. Basically I want to find table height.Any confusion please let me know.
推荐答案
使用 filter()
。
console.log($(data).filter('table'));
假设数据
是一个 HTML
,你可以这样做:
Presuming that data
is a string of HTML
, you can do this:
$(data).find('table');
这将返回表
而不添加数据到 DOM
。
That will return the table
without adding the data to the DOM
.
这篇关于Jquery find不能处理AJAX返回数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!