Skip to content Skip to sidebar Skip to footer

In Which Scieno I Need To Use Async: False, Or Async: True In Jquery Ajax Method

i am wondering where i need to use async: false, or async: true Jquery Ajax Method i have one form with fields and when i click on button i am calling jquery ajax method to save

Solution 1:

here are the use cases. from the docs.

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. As of jQuery 1.8, the use of async: false with jqXHR ($.Deferred) is deprecated; you must use the success/error/complete callback options instead of the corresponding methods of the jqXHR object such as jqXHR.done() or the deprecated jqXHR.success().

Async

  1. when you are doing Cross Domain Request.
  2. this is the default setting for $.ajax.

Sync :

  1. When you want to finish the request of ajax call i.e means one request after another. which is not recomennded.

Async in jquery

Solution 2:

Async : The ajax response you are trying to get has no dependency on next task you are doing.

Sync: The ajax response you are trying receive has dependency on the next task you are doing.

Post a Comment for "In Which Scieno I Need To Use Async: False, Or Async: True In Jquery Ajax Method"