跨域ajax调用Windows身份验证在chrome中工作,而在Firefox中不工作 [英] Cross domain ajax call windows authentication working in chrome and not working in Firefox
问题描述
我有使用Windows身份验证的WCF服务,并且我使用ajax调用来调用此服务.对于谷歌浏览器,它是完美的工作,因为凭据已兑现,但是在Firefox中,我得到了401未经授权.我希望firefox会弹出一个弹出窗口来填充我的凭据(就像我从浏览器中调用服务时一样).
I have WCF service that uses windows authentication and I call this service with ajax calls. For google chrome it is work perfect as the credential are cashed but in firefox I get 401 unauthorized. I would expect that firefox will pop a pop up to fill in my credential(like when I invoke the service from the browser).
我的JavaScript代码如下:
my javascript code is as follows:
var url = "http://localhost:8732/Domain.WebServices/MyService/web/MyFunction";
$.ajax({
type: "GET",
url: url,
crossDomain: true,
processData: false,
xhrFields: {
withCredentials: true
},
error: function (XMLHttpRequest, textStatus, errorThrown) { alert('failed'); },
success: function (data) { onSuccess(data); }
});
当凭据未兑现时,如何在Firefox中工作?
how can I make it work in firefox when the credentials not cashed?
推荐答案
根据官方文档,您必须确保服务器以Access-Control-Allow-Credentials:true标头响应,否则Firefox将拒绝任何响应.
According to the official docs you have to ensure that server responds with Access-Control-Allow-Credentials: true header, otherwise Firefox will reject any response.
我不确定firefox是否内置了显示弹出窗口的功能,您应该自己实现它.
I am not sure that firefox has built in functionality to show popup and you should implement it yourself.
在此处中查看更多示例.
这篇关于跨域ajax调用Windows身份验证在chrome中工作,而在Firefox中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!