【发布时间】:2010-05-12 13:28:39
【问题描述】:
我正在使用 jquery ajax $.get,它在我的服务器上调用一个 php 脚本并从另一个站点(域)检索内容。它返回完整的网页。然后我想使用 .find() 方法从“中心”标签中提取 html 数据,但我遇到了一些问题。
$("#btnGetData").click(function(){
$.get("pgiproxy.php",{ data: $("#formdata").serialize() },
function(result) {
alert($(result).find('center').html());
val = $(result).find('center').html();
alert(val);
$('#BFX').html(result);
alert( $('#BFX').find('center').html() );
});
});
前 2 个方法都返回“null”,但是当我将 ('result') html 插入 #BFX div 时,它在我的显示器上正确显示,最终警报正常工作,它 find()s the 'center ' 标记并在警报中显示 html 数据。
在尝试从返回的 ajax 数据“结果”中“查找()”“中心”标签时,任何人都可以看到为什么我返回“空”(如前 2 个警报)。
感谢任何帮助
尼克。
【问题讨论】:
-
我不习惯jquery,但是
result.find('center').html()应该不行? -
您是否转储了 'result' 的内容?您可以尝试在回调后设置数据类型 'html' $.get('foo', {}, function(){}, 'html');
-
嗨 jAndy,我将数据类型设置为 'html',使用 --alert($(result).find('center').html()); 的结果仍然相同; --,返回null。