Ajax request has invalid characters.

I created an AJAX request. In new browsers, it works fine, but IE7 tells me that there is an error with characters in the line where function: 'gettestvaraibles'it stands. Can someone tell me where the error might be?

$.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() {
    }
});
+5
source share
2 answers

Function is a reserved keyword. You need to either change it or wrap it in quotation marks:

data: {
    "function": 'gettestvaraibles',
    "game_id": '630',
    "game_score": '50'
},
+6
source

You must put quotation marks around functionbecause this is a keyword in JavaScript:

data: {
       'function': 'gettestvaraibles',
       'game_id': '630',
       'game_score': '50'
}
+1
source

All Articles