lever / postings-api

API documentation and examples for the lever postings REST API
184 stars 38 forks source link

Not working in IE11 #23

Closed jmtame closed 7 years ago

jmtame commented 7 years ago

The response comes back as a string in IE11 and needs to be parsed. This fixed it for me:

request.onload = function() {
    if (request.status == 200) {
      if (typeof(request.response) === 'string') {
        createJobs(JSON.parse(request.response));
      } else {
        createJobs(request.response);
      }
    } else {
      console.log("Error fetching jobs.");
    }
  };
rkstedman commented 7 years ago

@jmtame Thanks for reaching out!

I see you're checking for when the response is a string and otherwise treating as already parsed. I'm assuming that in browsers like Chrome/Firefox the response is returned already parsed and in IE11 it's returned as a string. Is that correct?

I imagine it's likely a configuration of the request and the defaults are different in each browser. I'm assuming the request you're using is this one?

It looks like there might be a way to specify the response type explicitly: https://xhr.spec.whatwg.org/#the-responsetype-attribute

I run into a similar issue regularly when I'm using the request library in Node. If you know you're expecting JSON, you can add an option {json: true} and it will provide the response already parsed. Otherwise, the response is provided as a string and you can parse it yourself.

Hope this helps!

jmtame commented 7 years ago

Hi @rkstedman - thanks for the reply. I tried setting the responseType to json but that didn't work. Looks like an issue that Microsoft is aware of, but not fixing at the moment.