我正在使用一个简单的 ajax 加载程序来获取 wordpress 上的内容。
$("#page_preview").load("ajaxloader/", function(response, status, xhr) {
if (status == "error") {
alert("Sorry but there was an error");
}
else
{
$('#page_preview').fadeIn(300);
}
});
return;
当我加载一个嵌入了谷歌地图的特定帖子时,显然出了点问题但是而不是进入if
语句, Firebug 表明它超出了这个代码。 if
或 else
均未命中。
使用 eclipse 调试器我发现页面加载成功,但是当它返回数据给 .load()
方法时,最后一个中断。
对可能发生的事情有什么想法吗?
最佳答案
如何
<script>
// as of jQuery 1.5.x ++
var pagePreview = $("#page_preview");
$.get("ajaxloader/").success(
function(response, status, jqXhr) {
alert("Success!");
pagePreview.empty();
pagePreview.append(response);
// i feel you need to parse the response for the google map div, and perform another $.get() of the google url?
}).error(function(response, status, jqXhr) {
alert("These are not the droids you are looking for. move along.");
}).complete(function(response, status, jqXhr) {
alert("Complete!");
});
</script>
#为什么
jQuery.load()将使您了解文档。 .load 相当于这个
It is roughly equivalent to $.get(url, data, success) except that it is a method rather than global function and it has an implicit callback function. When a successful response is detected (i.e. when textStatus is "success" or "notmodified"), .load() sets the HTML contents of the matched element to the returned data.
您需要在 $.ajax( complete:function(responseText, textStatus, XMLHttpRequest))){});
中注册并检查 textStatus
值。如果可以,则自己将数据加载到目标 $('selector')
中。或者通过在 chrome 中观察网络 xmlHttpRequests (ctrl + shift +j) 或在 firebug 中的一些网络选项卡来修复 .load()
并使用 $( 'selector').load( 'url', function(response, status, xhr){})
关于php - jQuery .load 怎么会失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7433659/