使用jQuery的同步ajax调用在firefox上不工作

synchronous ajax call using jQuery not working on firefox

本文关键字:firefox 工作 调用 jQuery 同步 ajax 使用      更新时间:2023-09-26

我试图使ajax调用设置异步属性为false,但它得到错误,而它在chrome和ie上工作。

我知道Firefox强烈推荐异步ajax调用由于用户体验问题,但我需要得到响应之前继续做其他事情和它的ok(和强制)等待,直到收到响应…

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

    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都可以正常工作

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