1

This is the strangest bug I've encountered.

I submit an ajax POST that would retrieve some data.

$.ajax({
   url: url,
   data: data,
   type: 'POST',
   success: function(data){
       console.log(data)
   },
   dataType: 'json',
   contentType: 'application/json; charset=utf-8'
}
)

In other version of IE and Chrome, the code would work fine and give the value of data which is {"success": true}.

But in IE8, data would return undefined . However, if I do JSON.stringify(data) , it would return {"success":true}.

I tried to convert the returned string to object via $.parseJSON(JSON.stringify(data) but it returned undefined again.

What can I do to get the response data as an object like I would normally in other browser?

EDIT:!! Found the solution. Apparently, the IE8 emulation of IE11 is a total crap and cannot display data correctly. Using IE8 on a virtual machine would correctly display the data and I figured out why it was undefined. Thanks for the help!

17
  • Set dataType: 'json', in case the mimetype isn't correctly set in the response header. Also, you're missing a { Commented Jan 3, 2014 at 22:40
  • Is this in actual IE8, or in a newer version in IE8 mode, as console doesn't seem like a good idea in IE8, it only works with the console open ? Commented Jan 3, 2014 at 22:41
  • IE11 using IE8 mode, and in my real code I actually use dataType and contentType appropriately Commented Jan 3, 2014 at 22:42
  • What jQuery version do you use? Commented Jan 3, 2014 at 22:43
  • Check the error callback. That's probably where you're ending up in IE8. And as I said above; you're still missing a { Commented Jan 3, 2014 at 22:44

2 Answers 2

1

Found the solution! Apparently, the IE8 emulation of IE11 is a total crap and cannot display data correctly. Using IE8 on a virtual machine would correctly display the data and I figured out why it was undefined. Thanks for the help!

Sign up to request clarification or add additional context in comments.

Comments

0

I'm not sure that you need to do that in IE8. Here is some code that I use with success in IE8 on a website that is live that is using jQuery 1.10.2:

$.ajax({
    type: "POST",
    crossDomain: true,
    url: 'http://example.com/service/url',
    data: params,
    dataType: 'json',
    timeout: 10000
})
.done(function( data ) {
    console.log("Success");
    console.log(data.success);
}) 
.fail(function( data ) {
    console.log("Rejected");
    console.log(JSON.stringify(data));
});

Hopefully this example is helpful for you to see how to handle the jQuery callback. The object that comes back is already an object if the result is actually valid JSON.


Updated this to be more generic of an answer.

2 Comments

This has quite a lot of rows that OP surely won't need. self for instance.
Updated this to be more generic of an answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.