Javascript的Ajax调用使用的密码有特殊字符 [英] Javascript Ajax call using password with special characters

查看:194
本文介绍了Javascript的Ajax调用使用的密码有特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JavaScript的网页,使一个Ajax调用如下面的code。 PHP的页面是一个企业内部网,并要求身份验证的域(基本身份验证是不允许的)。我收集使用jQuery输入字段的用户名(U)和密码(P)。

I have a JavaScript page that makes an Ajax call like the code below. The PHP page is inside a corporate intranet and requires authentication in the domain (basic auth is disallowed). I collect the username (u) and password (p) from input fields using jQuery.

var u = $('#user').val();
var p = $('#pass').val();

$.ajax({
    url: "http://mydomain/mypage.php",
    username: u,
    password: p,
    error: function () {
    }
}).done(function(html) {
        //Do Stuff
});

解决方案的工作非常好......除了当用户在他们的密码特殊字符。到目前为止,似乎我们正在受:@ $ +

The solution works very well...except when the user has a special character in their password. So far, it seems we're affected by: @ $ +.

在我看来,有一些冲突收集密码的符号也充当句法运营商在JavaScript ...但你如何正确逃生它们提交的密码吗?

It seems to me there is some conflict collecting passwords with symbols that also act as syntax operators in JavaScript...but how do you properly escape them to be submitted as a password?

谢谢!

推荐答案

您将不得不URL连接code中的参数。对于JavaScript的,看看<一href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/en$c$cURIComponent"相对=nofollow>恩codeURIComponent 。后端框架会明白,所以不用担心。

You will have to URL encode the parameter. For JavaScript, take a look at encodeURIComponent. Backend framework will understand it, so don't worry about that.

这篇关于Javascript的Ajax调用使用的密码有特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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