我有以下脚本供AJAX登录,但是有些密码包含“!@#”等字符,它将返回403错误,不会提交给PHP。
$(document).ready(function () { // When the document is ready
$('#login').click(function (e) { // We attach the event onchange to the select element
e.preventDefault();
var form_info = "";
$('#login_form *').filter(':input').each(function(){
if(this.value !== ""){
form_info += this.name;
form_info += "=";
form_info += encodeURIComponent(this.value);
form_info += "&";
}
});
form_info += "function_name=login";
var form = $('#login_form').serialize() + "&function_name=login";
$.ajax({
url: "function_ajax.php", // path to you php file
type: "post", // We want a POST request
dataType: 'html',
data: form_info,
statusCode:
{
404: function () {
alert('Could not contact server.');
},
500: function () {
alert('A server-side error has occurred.');
}
},
error: function ()
{
alert('A problem has occurred.');
},
beforeSend: function ()
{
alert(form_info);
alert(form);
},
complete: function ()
{
},
success: function (data) { // The function to execute if the request is a -success-,
if(data === "1"){
if (document.referrer !== "") {
window.location.href = document.referrer;
}
else{
window.location.href = "some_domain"
}
}
else if (data === "2")
{
alert("invalid");
}
else {
alert("empty");
}
}
});
});
});
你会发现我正在尝试两种方式来编码每个元素和序列化只是为了检查我是否得到相同的结果,并且我得到了相同的结果,但是,它仍然是这个错误。< / p>
如果我尝试编码整个序列化,那么我不会得到错误,但在PHP中,$ _POST数组将第一个键作为我发送的数据没有任何值。
encodeURIComponent($('#login_form').serialize()) + "function_name=login"
然后$ _POST就像
array(
[email=email@gmail.com&password=pass123!@#&function_name=login]=>
)
这对我没用。