user2457035
user2457035

Reputation: 81

IE9+ is messing up my JSON object

I was furious when i could not figure out why my app was working fine in Chrome but not IE. After hours of looking at my back end making sure my JSON was coming through to each browser correctly, I noticed this.

In Chrome the JSON object is parsed fine, except in IE9+ it added QUOTES around my Array! Here is the complete ajax call

var jsonTop = [];
var jsonBot = [];

$.when(
    $.ajax({
        url: 'http://localhost:999/empleplrestop',
        success: function(dataTop) {
            jsonTop = dataTop;
        }
    }), 
    $.ajax({
        url: 'http://localhost:999/empleplresbot',
        success: function(dataBot) {
            jsonBot = dataBot;
        }   
    })
).then(function() {
    loadTable();
});

As you can see, at the success: function(dataTop/Bot) is where it is adding it.

but in IE the JSON object requested through the AJAX was perfectly fine! (its just mock data)

Am I using $.when wrong? The Quotes are messing up my array!

Upvotes: 2

Views: 78

Answers (1)

Barmar
Barmar

Reputation: 781848

Add the dataType: option to specify that the result is JSON:

$.ajax({
    url: 'http://localhost:999/empleplrestop',
    dataType: 'json',
    success: function(dataTop) {
        jsonTop = dataTop;
    }
}), 

Upvotes: 5

Related Questions