Search code examples

Deprecation Synchronous XMLHttpRequest

I see this error: "[Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check", on this code:

var request;
    request = new XMLHttpRequest();
    request = new ActiveXObject("Microsoft.XMLHTTP");
}'GET', '', false);

What should I replace the instructions with because they are deprecated?


  • you just need to change'GET', '', false);

    to'GET', '', true);

    This will make the request operate asynchronously, meaning the code after it is sent will execute immediately instead of waiting for the request to complete. You can then use an event listener to tell the request what code to run when it's complete.

    request.onreadystatechange = function () {
        if(request.readyState === XMLHttpRequest.DONE) {
            console.log("Request completed!");