Javascript Ajax call using password with special characters

本小妞迷上赌 提交于 2019-12-11 10:08:09

问题


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: @ $ +.

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?

Thanks!


回答1:


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.



来源:https://stackoverflow.com/questions/14445631/javascript-ajax-call-using-password-with-special-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!