gpt4 book ai didi

html - Firefox 不支持 withCredentials 属性

转载 作者:太空狗 更新时间:2023-10-29 16:51:49 24 4
gpt4 key购买 nike

我正在使用 HTML5、jQuery 1.6.1、jQuery Mobile 1.0.1。

我正在使用以下代码发出 Ajax 请求。它在 Chrome 中运行良好,但在 Firefox 14.0.1 中测试时出现以下错误。

Use of XMLHttpRequest's withCredentials attribute is no longer supported in the synchronous mode in window context.

代码:

$.ajax({
type: "GET",
dataType: "json",
async: false,
beforeSend: function (xhr){
xhr.setRequestHeader('Authorization', make_base_auth(UserId, Password));
},
xhrFields: {
withCredentials: true
},
success:function(data){
console.log("Success");
},
error:function(xhr,err){
console.log("Failed" );
}
});

请帮我解决这个问题。

最佳答案

解决方案很简单:不要在 $.ajax 中使用 async: false

它在较新的版本中已被弃用,您不需要它。使用它总是一个坏主意。执行您需要对成功回调的结果执行的操作(就像您的 console.log)。

来自 the documentation (1.8):

Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active. As of jQuery 1.8, the use of async: false with jqXHR ($.Deferred) is deprecated; you must use the complete/success/error callbacks.

关于html - Firefox 不支持 withCredentials 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12472395/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com