问题
I've tried this two ways.
Way 1
function Login() {
var email = encodeURIComponent($("#loginemail").val());
var pass = encodeURIComponent($("#password").val());
$.ajax({
url:"/user/login",
type: "POST",
data: {email:email, password:pass},
dataType: "json"
}).done(LoginDone);
//$.post("/user/login", {email:email, password:pass}, LoginDone);
}
Way 2
function Login() {
var email = encodeURIComponent($("#loginemail").val());
var pass = encodeURIComponent($("#password").val());
$.post("/user/login", {email:email, password:pass}, LoginDone);
}
Both ways work fine on chrome, but for some reason with IE it doesn't send the data {email:email, password:pass} in the POST, or at all.
I've tried both on a local server, and on a live webserver, both with the same results.
Using IE10 here.
回答1:
data: {email:email, password:pass}
should be
data: {"email":email, "password":pass}
You are passing the value of the variables as the key so if your server-side resource is expecting email it is actually seeing the value of that variable encodeURIComponent($("#loginemail").val()).
This is likely not an IE10 issue, this shouldn't work as written in any browser.
Update
This answer may no longer be applicable due to bug fixes in IE 10.
Please disregard this answer it is wrong and cannot be deleted due to being accepted.
回答2:
Can't fix @jQuery bug tracker: AJAX Post on IE10 / Windows 8
回答3:
After deep debuggind I found a workaround for IE10 AJAX POST Bug:
do not use POST with GET.
$.post("Page.aspx?action=edit",a,function(data) {dataRow[0]=data; GoToShowMode(row)});
change to
a.action=edit;
$.post("Page.aspx",a,function(data) {dataRow[0]=data; GoToShowMode(row)});
回答4:
IE-10 does not work data serialize => $(this).serialize()
$('#formLogin').submit(function () {
$.ajax({
url: this.action,
type: this.method,
data: $(this).serialize(),
cache: false,
success: function (data) {
var val1 = "";
var val2 = "";
$.map(data, function (item) {
val1 = item.success;
val2 = item.URL;
});
if (data[0].messageCode == "success") {
GoGO(data[0].URL);
}
else {
alert(data[0].message);
}
}
});
return false;
});
For this you can use this line on _layOut.chtml before metatag. So, IE-10 works just like IE-9.
<meta http-equiv="x-ua-compatible" content="IE=9" >
回答5:
Try this: http://code.gishan.net/code/solution-to-ie10-ajax-problem Works for me. This is a known issue of IE10.
回答6:
I've had the same problem with IE 10 (10.0.9200.16521) on Win7 x64 SP1. I've solved the problem simply by using a newer version of jQuery (1.9.1 in place of 1.8.3)
来源:https://stackoverflow.com/questions/11235613/jquery-ajax-post-not-working-ie10