如何防止 Firefox 使用 JQuery AJAX 使用 HTTP 基本身份验证提示输入用户名/密码? [英] How do I keep Firefox from prompting for username/password with HTTP Basic Auth with JQuery AJAX?

查看:29
本文介绍了如何防止 Firefox 使用 JQuery AJAX 使用 HTTP 基本身份验证提示输入用户名/密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些浏览器端动态功能并使用 HTTP 基本身份验证来保护一些资源.用户体验非常重要,而且是高度定制化的.

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.

这是一个简单的 JQuery 测试方法,最终将测试用户是否在表单中提供了正确的凭据:

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;
  });
});

如果不允许他们访问 /private,此时他们应该只看到警告框.但是,在 Firefox 上,会弹出浏览器提供的登录表单(以使用新凭据重试).Safari 不会这样做.

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.

我们希望完全控制自定义表单、淡入淡出、过渡等的体验.如何才能不显示 Firefox 的默认框?(如果在我们测试 IE 时这会成为问题,我也很想听听那里的解决方案.)

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.)

推荐答案

如果你还没有阅读它:

如何抑制浏览器的身份验证对话框?

看起来不太乐观:)

这篇关于如何防止 Firefox 使用 JQuery AJAX 使用 HTTP 基本身份验证提示输入用户名/密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆