Hiba
Hiba

Reputation: 251

Why ajax call give error of Synchronous XMLHttpRequest on the main thread is deprecated?

I am doing assignment in ASP.net MVC5. When i do ajax call it successffully go to action method(debugged). But after that when i make markup of something it and append to the body it give the error in jquery min.js and the error on console is : Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. jquery-1.11.0.min.js:4 Uncaught ReferenceError: $document is not defined

My code is below:

$.ajax({
            url: url,
            type: "GET",
            contentType: "application/json; charset=utf-8",
            cache: false,
            async: false,
            success: function (data, status) {
                if (status && data) {
                    var Markup = data;
                    var Title = Id && Id != null ? "edit" : "New";
                    $AddEdit = BootstrapModal.createAndShow("modal", Title, Markup); // this is another method in JS
                }
            },
            error: function () {
                alert("not workig");
            }
        });

Bootstrap method is:

var createAndShow = function (ElementId, Title, Markup) {
        debugger;

      //Here some markup is creating and append to body

        $("body").append(Markup); //Here error come

Upvotes: 1

Views: 1587

Answers (1)

Julius R.
Julius R.

Reputation: 57

The error you are facing: "Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience. For more help http://xhr.spec.whatwg.org/"

says it all. You are using a synchronous Ajax Call, by setting it explicitly in this line:

async: false,

This is deprecated. If applicable, change it to true. There are however very rare cases, where a synchronous ajax call might be useful.

Upvotes: 1

Related Questions