$.ajax({
type: 'POST',
url: URL +'/foo/',
data: {'pass': pass},
dataType: "json",
jsonp:'jsonp_callback',
success: function(data) {
if (data["success"] === "false") {
$("#password").val("");
$('.error-message').removeClass('hide')
$('.error-message').addClass('show')
}
else {
var tempUrl="http://10.0.1.101:9000/bar/"
location.href=tempUrl;
}
},
});
return false
This is working fine in Mozilla, Chrome, Safari. But Not in IE. What could be the reason. I am returning suucess value from server. If success is True it will redirect to tempUrl
.
But nothing is happing here in IE. It seems that ajax is no开发者_如何学Pythont at all working in IE.
You're running into the "dangling comma" problem (the comma after the closing }
of your success
parameter). IE doesn't like dangling commas in object literals, it treats them as syntax errors and your script dies. (This isn't an IE bug, it's a reasonable interpretation of the earlier spec; the newest spec specifically allows the comma, though, and this is fixed in IE8.) Off-topic: IE has a similar, but different, issue with dangling commas in array literals (which is still in IE8).
More on both isuses this article, but basically:
$.ajax({
type: 'POST',
url: URL +'/foo/',
data: {'pass': pass},
dataType: "json",
jsonp:'jsonp_callback',
success: function(data) {
if (data["success"] === "false") {
$("#password").val("");
$('.error-message').removeClass('hide') // <== Strongly recommend ; here
$('.error-message').addClass('show') // <== Another ; here
}
else {
var tempUrl="http://10.0.1.101:9000/bar/" // <== Another ; here
location.href=tempUrl;
}
}, // <== This comma is the problem
});
return false // <== Another ; here
See the note near the bottom. Remove the comma and you're fine. Things are improving (as outlined in the linked article above), but for maximum compatibility in the wild, you need to watch this for a while longer.
(The other notes are off-topic, but again, strongly recommend fixing those as well, never rely on semicolon insertion.)
You should add semicolons in the end of these lines:
$('.error-message').removeClass('hide')
$('.error-message').addClass('show')
var tempUrl="http://10.0.1.101:9000/bar/"
精彩评论