如何通过HTTP Basic Auth和JQuery AJAX来阻止Firefox提示用户名/密码? [英] How do I keep Firefox from prompting for username/password with HTTP Basic Auth with JQuery AJAX?
问题描述
下面是一个简单的测试JQuery方法,最终将测试用户是否以一种形式提供了正确的凭证: ()函数()函数()函数()函数()函数() ($('#username')。val()+':'+ $('#password')。val());
$ .ajax({
url:'/ private',
方法:'GET',
async:false,
beforeSend:function(req){
req.setRequestHeader('Authorization ';'test:password');
},
error:function(request,textStatus,error){$ b $ if(request.status == 401){
alert '401');
}
}
});
return false;
});
});
如果不允许访问 / private
目前他们应该只看到警戒框。但是,在Firefox上,会弹出一个浏览器提供的登录表单(用新凭据重试)。 Safari不会这样做。
我们希望完全控制自定义窗体,淡入淡出,转换等等的体验。我怎样才能保持Firefox的默认框不被显示? (如果我们测试IE的时候会遇到这个问题,那么我也很乐意听到解决方案。)
如果你还没有阅读:看起来不太可能:)
I'm writing some browser side dynamic functionality and using HTTP Basic Auth to protect some resources. The user experience is very important and is highly customized.
Here's a simple test JQuery method that eventually will test if a user has supplied the right credentials in a form:
$(document).ready(function() {
$("#submit").click(function() {
var token = Base64.encode($('#username').val() + ':' + $('#password').val());
$.ajax({
url: '/private',
method: 'GET',
async: false,
beforeSend: function(req) {
req.setRequestHeader('Authorization', 'test:password');
},
error: function(request, textStatus, error) {
if (request.status == 401) {
alert('401');
}
}
});
return false;
});
});
If they are not allowed to access /private
, at the moment they should see just the alert box. However, on Firefox, a browser-provided login form pops up (to retry with new credentials). Safari does not do this.
We want to completely control the experience with custom forms, fades, transitions, etc. How can I keep Firefox's default box from being shown? (If this will be an issue when we test for IE, I'd love to hear solutions there, too.)
In case you haven't read it:
How can I supress the browser's authentication dialog?
Doesn't look too promising :)
这篇关于如何通过HTTP Basic Auth和JQuery AJAX来阻止Firefox提示用户名/密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!