Is jQuery $ .post () asynchronous?

Is $ .post asynchronous? So if I were to make such commands below, would they all be done at the same time, and not synchronously (1, then, then, then, etc.)?

$(document).ready(function() {
    var variable1 = '1';
    var variable2 = '2';
    var variable3 = '3';
    var variable4 = '4';

    $.post("process.php", {element1: variable1}, function(data){
        $("#area1").html(data);
    });

    $.post("process.php", {element2: variable2}, function(data){
        $("#area3").html(data);
    });

    $.post("process.php", {element3: variable3}, function(data){
        $("#area4").html(data);
    });

    $.post("process.php", {element4: variable4}, function(data){
        $("#area4").html(data);
    });
});
+4
source share
3 answers

The answer to this question is trivial, and in the sentence it can be answered as

All ajax request are asynchronous operations, which is proposed by the abbreviation. (Asynchronous Javascript and XML)

You can link to the api $ .post () documentation in the jQuery website

Which clearly indicates that

This is an abbreviated Ajax function that is equivalent to:

$.ajax({
  type: "POST",
  url: url,
  data: data,
  success: success,
  dataType: dataType
});

, XML ​​ MIME . .

, $.post() .

jQuery- < 1.8 async:false, . . ,

jquery >= 1.8 .done(). , ajax-

+3

$.post()

, , . . $.post() $.ajax(), :

$.ajaxSetup({async: false});  
$.post();

async true. !

+3

The most elegant solution for what you want to do is to save all the data in one JSON and send it to your php and then reply to other JSON and decode the data so that you can update everything in one call, I would encode it, but I don't know how your php or html works.

+1
source

Source: https://habr.com/ru/post/1671459/


All Articles