Non-blocking Synchronous AJAX

前端 未结 5 1588
醉梦人生
醉梦人生 2021-01-19 05:38

Is there a way to perform a synchronous AJAX query that doesn\'t freeze the browser? In my opinion synchronous requests are a lot easier to work with in most cases, but the

5条回答
  •  感动是毒
    2021-01-19 06:21

    I don't think it is possible. Instead of trying to use synchronous queries, you can use the asynchronous approach and use the AJAX done event.

    Example using jQuery.ajax()

    jQuery.ajax({
        url: "URL HERE",
        data: "whatever you are sending"
    }).done(function (data) {
        // Do things with data
    });
    

    So, instead of using a synchronous request, you can use the Asynchronous request and just execute code AFTER the request has completed. So, it won't freeze your browser.

提交回复
热议问题