locked
Difference between async:false and async:true in ajax RRS feed

  • Question

  • User1668729249 posted

    hi,

    $.ajax({

    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "MasterService.asmx/InoutReport",
    datatype: "JSON",

    async:false
    success: function (data) {
    var div = $("#test").empty();
    $(data.d).each(function (index, item) {

    });
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
    debugger;
    }
    });

    thanks..

    Saturday, November 9, 2013 3:23 AM

Answers

  • User879079649 posted

    Setting async to false means that the statement you are calling has to complete before the next statement in your function can be called. If you set async: true then that statement will begin it's execution and the next statement will be called regardless of whether the async statement has completed yet.

    http://stackoverflow.com/questions/1478295/what-does-async-false-do-in-jquery-ajax

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 9, 2013 3:27 AM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 9, 2013 3:29 AM
  • User-1635195291 posted

    Hi stsan,

    You should mostly always use an asynchronous Ajax Request, in fact I know only about one place where a synchronous Ajax Request should be used which is if you're in an Ajax Request embedding a new JavaScript file on the client and then referencing types and/or objects from that JavaScript file in the return from the original Ajax Request. Then the fetching of this new JS file should (or can sanely) be included through using a synchronous Ajax Request...

    Other then that you should always use asynchronous Ajax Requests. The most important reason is that a synchronous Ajax Request makes the UI (browser) unresponsive...

    Source: http://stackoverflow.com/questions/1052453/ajax-requests-synchronous-vs-asynchronous

    Hope this helps.

    Thanks,

    Jatin

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 11, 2013 9:04 PM
  • User555306248 posted

    async(default:

    true

    )

    <div>Type: Boolean</div> <div>By default, all requests are sent asynchronously (i.e. this is set to

    true

    by default). If you need synchronous requests, set this option to

    false

    . Cross-domain requests and

    dataType: "jsonp"

    requests do not support synchronous operation. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active</div> <div> </div> <div>http://api.jquery.com/jQuery.ajax/</div>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 12, 2013 1:03 AM

All replies

  • User879079649 posted

    Setting async to false means that the statement you are calling has to complete before the next statement in your function can be called. If you set async: true then that statement will begin it's execution and the next statement will be called regardless of whether the async statement has completed yet.

    http://stackoverflow.com/questions/1478295/what-does-async-false-do-in-jquery-ajax

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 9, 2013 3:27 AM
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, November 9, 2013 3:29 AM
  • User-1635195291 posted

    Hi stsan,

    You should mostly always use an asynchronous Ajax Request, in fact I know only about one place where a synchronous Ajax Request should be used which is if you're in an Ajax Request embedding a new JavaScript file on the client and then referencing types and/or objects from that JavaScript file in the return from the original Ajax Request. Then the fetching of this new JS file should (or can sanely) be included through using a synchronous Ajax Request...

    Other then that you should always use asynchronous Ajax Requests. The most important reason is that a synchronous Ajax Request makes the UI (browser) unresponsive...

    Source: http://stackoverflow.com/questions/1052453/ajax-requests-synchronous-vs-asynchronous

    Hope this helps.

    Thanks,

    Jatin

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 11, 2013 9:04 PM
  • User555306248 posted

    async(default:

    true

    )

    <div>Type: Boolean</div> <div>By default, all requests are sent asynchronously (i.e. this is set to

    true

    by default). If you need synchronous requests, set this option to

    false

    . Cross-domain requests and

    dataType: "jsonp"

    requests do not support synchronous operation. Note that synchronous requests may temporarily lock the browser, disabling any actions while the request is active</div> <div> </div> <div>http://api.jquery.com/jQuery.ajax/</div>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 12, 2013 1:03 AM