Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax request has invalid characters

Tags:

jquery

ajax

I created an AJAX request. In the new browsers it works fine, but IE7 tells me there is an error with characters in the line, where function: 'gettestvaraibles' stands. Can someone tell me where the error could 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() {
    }
});
like image 657
user1238115 Avatar asked Apr 12 '12 07:04

user1238115


2 Answers

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

data: {
    "function": 'gettestvaraibles',
    "game_id": '630',
    "game_score": '50'
},
like image 140
Rory McCrossan Avatar answered Sep 21 '22 16:09

Rory McCrossan


You should put quotes around function, because it's a keyword in JavaScript:

data: {
       'function': 'gettestvaraibles',
       'game_id': '630',
       'game_score': '50'
}
like image 30
Gabi Purcaru Avatar answered Sep 21 '22 16:09

Gabi Purcaru