Ryan Mcguinn
Ryan Mcguinn

Reputation: 825

Deprecation Synchronous XMLHttpRequest Error Message

So I've been getting this in my console app.js:159 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.

I was looking for a way to parse JSON into a url and came across this code block, which seems to be throwing the error.

function readJSON(file) {
  const request = new XMLHttpRequest();
  request.open('GET', file, false);
  request.send(null);
  if (request.status == 200)
  return request.responseText;
};

After a bit of research I came across setting async = true but didn't have any luck with that.

Also, as a side note, my app uses HTML Geolocation and it's not working on GitHub Pages, but works fine locally. Any ideas on that? Thanks

Upvotes: 1

Views: 3994

Answers (1)

Jeff J
Jeff J

Reputation: 111

Toggle false to true. Syntax: XMLHttpRequest.open(method, url, async)

 request.open('GET', file, true);
 request.onload = function() { 
   //response is available as request.response here
}  

Upvotes: 2

Related Questions