People, tell me, in jQuery, the $ .post request is synchronous ?? I know that in $ .ajax there is an async attribute, and what about $ .post ??



    1 answer 1

    $ .post () and $ .get () are abbreviated versions of the $ .ajax () function and, by default, all requests occur asynchronously.

    PS From myself would add - if you use Ajax several times in the script, it is better to use the full version. Plus, you can create general settings for queries using $ .ajaxSetup . Then you will get rid of excesses in the code, in fact you will get the same abbreviated versions, but insure against unexpected behavior in the execution of the script. For example, in advance we prescribe the path to the php-handler, the format in which we will receive the answer, the type of the executed request (GET or POST), well, let's say synchronous / asynchronous data transfer:

    $.ajaxSetup({ url: '/handler.php', async: true, type: 'POST', dataType: 'json' }); 

    Everything! Now we are in any ajax request, just add the data to be transmitted and process the response received:

     $.ajax({ data: {key: val}, success: function(data){ console.log(data); } }); 
    • thanks for the advice! I do not use Ajax at all. by default, i.e. this setting cannot be changed for $ .post ??? - deathr0w
    • @ deathr0w777, As far as I know, no. Although, why not try: $ .post ('handler.php', {async: false}, function (data) {console.log (data);}); And why do you need a synchronous mode? This can lead to blocking the page until the request is completely completed. - Deonis