【问题标题】:synchronous ajax call using jQuery not working on firefox使用jQuery的同步ajax调用在firefox上不起作用
【发布时间】:2015-10-20 08:45:41
【问题描述】:

我正在尝试进行 ajax 调用,将 async 属性设置为 false,但它在 chrome 和 ie 上工作时出错。

我知道由于用户体验问题,Firefox 强烈推荐异步 ajax 调用,但我需要在继续做其他事情之前获得响应,并且可以(并且强制)等待直到收到响应..

这是工作和不工作的代码,任何帮助将不胜感激。

    data = $.ajax({
        url: Common.serverPath + 'recovery/list',
        crossDomain: true,
        dataType: 'json',
        async: true,
        type: 'GET',
        contentType: 'application/json',
        xhrFields: {
            withCredentials: true
        }
    });
    setTimeout(function(){ console.log(data.statusText);
    },3000);

控制台:确定

    data = $.ajax({
        url: Common.serverPath + 'recovery/list',
        crossDomain: true,
        dataType: 'json',
        async: false,
        type: 'GET',
        contentType: 'application/json',
        xhrFields: {
            withCredentials: true
        }
    });
    setTimeout(function(){ console.log(data.statusText); },
    3000);

console:InvalidAccessError: 底层对象不支持参数或操作

chrome 和 ie 在两者中都可以正常工作

【问题讨论】:

标签: javascript ajax firefox asynchronous


【解决方案1】:

我发现“跨域请求和dataType:“jsonp”请求不支持同步操作。”即使它在 ie 和 chrome 中也是如此:)

【讨论】:

    猜你喜欢
    • 2016-04-23
    • 2014-09-10
    • 2016-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多