ajax调用不在firefox和chrome工作但在IE中工作

时间:2014-04-10 14:48:58

标签: jquery ajax internet-explorer google-chrome firefox

以下是在$(document).ready函数中调用的javascript。在IE中它的工作正常并返回记录,如在firefox和chrome中给出错误。但错误没有提供任何细节。它只是说就绪状态= 0,状态=错误,而responseText是空白的。

var surl = serviceUrl + trainingService + "GetLastUpdateDate/";

$.ajax({
    url: surl,
    dataType: 'json',
    success: function (data) {
        alert("SUCCESS:  " + data.d.length);
    },
    error: function (xhr, textStatus, error) {
        alert("readyState: " + xhr.readyState + "\nstatus: " + xhr.status);
        alert("responseText: " + xhr.responseText);
    }
});

正如有人在下面的评论中提到的是firebug调试器的屏幕截图,正如我之前提到的,它并没有提供太多细节。

firebug watch window

2 个答案:

答案 0 :(得分:0)

您的ajax是否向同一个域调用了请求?如果没有,您应该使用JSONP而不是JSON。

https://api.jquery.com/jQuery.ajax/

https://learn.jquery.com/ajax/working-with-jsonp/

此外,我已经看到IE将在哪里工作,如果ajax请求与请求页面的协议不同(如果页面为https且ajax调用为http),Chrome和Firefox将不会。

最后,您是否在Firefox和Chrome上安装了任何未安装在IE上的广告拦截插件?我已经看到一些广告拦截插件也会阻止ajax请求。

答案 1 :(得分:0)

我有这个问题,因为我正在使用<button onClick="doSomething()">button</button>导致页面进行回发,而不是使用<input type="button" onClick="doSomething()" value="button"/>完美地工作

相关问题