Ajax请求包含无效字符
问题描述:
我创建了一个AJAX请求。在新的浏览器中,它工作正常,但IE7告诉我,该行中的字符存在错误,其中function: 'gettestvaraibles'
代表。有人可以告诉我错误在哪里吗?Ajax请求包含无效字符
$.ajax('http://testurl/?eID=testid', {
data: {
function: 'gettestvaraibles',
game_id: '630',
game_score: '50'
},
type: 'post',
dataType: 'json',
error: function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
alert(errorThrown.message);
},
success: function() {
}
});
答
你应该把引号function
,因为它是在JavaScript关键字:
data: {
'function': 'gettestvaraibles',
'game_id': '630',
'game_score': '50'
}
答
功能是保留关键字。你需要改变它,或者把它换成引号:
data: {
"function": 'gettestvaraibles',
"game_id": '630',
"game_score": '50'
},
为什么有人用downvote这个答案? – p0rter 2012-04-12 08:01:08
谢谢,现在正在工作。 – user1238115 2012-04-12 13:38:55