1

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
4
  • 2
    Why ajax call give error of Synchronous XMLHttpRequest on the main thread is deprecated? - because synchronous XMLHttpRequest is deprecated in every modern browser Commented Sep 29, 2015 at 6:43
  • 1
    your other error $document is not defined - as the code you posted doesn't refer to $document anywhere, then I'd say that error is in code you have not posted Commented Sep 29, 2015 at 6:45
  • Jaomanda you are right. document ready was missing. Commented Sep 29, 2015 at 6:46
  • async: false should never be used. remove it and your error will be gone. Commented Sep 29, 2015 at 7:10

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.