Ajax请求包含无效字符

use*_*115 5 ajax jquery

我创建了一个AJAX请求.在新的浏览器中它工作正常,但IE7告诉我,行中的字符存在错误,其中显示 function: 'gettestvaraibles'.有人能告诉我错误可能在哪里吗?

$.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() {
    }
});
Run Code Online (Sandbox Code Playgroud)

Ror*_*san 6

函数是保留关键字.您需要更改它,或将其包装在引号中:

data: {
    "function": 'gettestvaraibles',
    "game_id": '630',
    "game_score": '50'
},
Run Code Online (Sandbox Code Playgroud)


Gab*_*aru 1

您应该在 周围加上引号function,因为它是 JavaScript 中的关键字:

data: {
       'function': 'gettestvaraibles',
       'game_id': '630',
       'game_score': '50'
}
Run Code Online (Sandbox Code Playgroud)