php - jQuery .load 怎么会失败?

标签 php jquery jquery-load

我正在使用一个简单的 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 表明它超出了这个代码。 ifelse 均未命中。

使用 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/

相关文章:

php - 使用ajax将数组发布到cakePHP中的 Controller

php - 通过邮件或 URL 发送带有随机哈希值的密码

jquery - 从嵌入的推文中删除关注按钮

javascript - 如何通过 JQuery 修改 CSS

javascript - JQuery 使用 .load() 替换整个 DIV

php - 任何易于使用的 php mysql datagrid?

php - 从 php mysql 传递数据以在同一页面上弹出

javascript - 从逗号分隔的对象中获取第一项

javascript - AJAX 加载内容后滚动条不起作用

javascript - Jquery .load/.empty 不从 div 加载和清空内容