question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IE11 not honoring responseType: 'json'

See original GitHub issue

I am trying to execute a simple xhr.get call and use the json object in response.body. This works fine in Chrome and Firefox, but in IE11; it does not convert the response.body into an object, but leaves it as a String. Here it only converts the response.body if isJson is set in the options ahead of time. I have no need for that property besides to hack it to work for IE11. Shouldn’t isJson be set to true if the responseType is ‘json’ or the json property exists?

Returns a string in response.body in IE11

xhr.get({
  url: myUrl?parameters,
  responseType: 'json'
}, callback);

My hack to convert response.body to an Object in IE11

xhr.get({
  url: myUrl?parameters,
  responseType: 'json',
  json: true
}, callback);

It looks like Microsoft is aware of it, but no fix coming for IE11.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
stloccommented, Jun 5, 2019

on IE don’t use xhr.responseType = 'json'; and parse yourself the response var res = JSON.parse(xhr.responseText);

var xhr = new XMLHttpRequest();
    //xhr.responseType = 'json';
    var params = ...
    xhr.open("POST", "/xxx", true);
    xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    xhr.onreadystatechange = function() {//Call a function when the state changes.
      if(xhr.readyState == 4 && xhr.status == 200) {
        var res = JSON.parse(xhr.responseText);
      }
    }
    xhr.send(params);
1reaction
TehShrikecommented, Jun 28, 2016

It has seemed pretty odd to me that you have to specify json: true even when the server is putting Content-Type:application/json headers on the response.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does setting XMLHttpRequest responseType before ...
Show activity on this post. Running new XMLHttpRequest(). responseType = "json" in the console throws an "InvalidStateError" exception in Firefox 26 and IE11 ......
Read more >
JSON stringify not working in IE11
Fixes LLK#654 IE does not honor responseType: 'json', and will not parse responses as JSON unless json data is present in the request....
Read more >
~soapdog/webextension-remove-twitter-trending-topics: initial ... - git
Since Spidermonkey does not fully parse the + // contents of a function ... new Error("api-metadata.json has not been included in browser-polyfill"); +...
Read more >
IE 11 asks to open or save JSON response - jQWidgets
and it works ok on IE and still works on Chrome. But in your experience is this the past way to handle this...
Read more >
Unable to retrieve blob from SQL database in IE11
responseType ='arraybuffer'" when I run it under IE11. ... I've googled the error message but could not figure out how to solve the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found