The difference between ajax asynchronous and synchronous

AJAX asynchronous

For example, in general, when a user registers, the user first has to fill out the form and then submit it, so that the form will make a request to the service, the server processes the code, and if the user exists, returns a message. In short, all the data needs you to submit, the information will be sent!

AJAX is equivalent to simulating a message sending request. You can find it when you register on many websites. For example, if you enter "123" in the username, it may prompt you that the user already exists, and the feeling is that the page is Did not refresh, that is, did not submit the form, and the user name is stored in the database, that is, to query the existence of the user name, you must send the user name in the form, and then in the database to query .

The process is handled by AJAX. The user enters the username. When the focus of the form changes, AJAX is triggered. Then AJAX simulates a GET or POST request to the server, and the server processes the data passed! And when the server is processing data, you can do other things, compare you can fill in the password or other!

The difference between ajax asynchronous and synchronous

The difference between Ajax synchronization and asynchronous

I have been thinking about the code running sequence when I encounter the AJAX load data when I write the JQUERY code. Recent projects have used AJAX synchronization. This synchronization means that when the JS code is loaded into the current AJAX, all the code in the page will be stopped, and the page will go out of the suspended state. When the AJAX is executed, the other code page will continue to run.

Asynchronous, when the AJAX code is running, other code can run.

Jquery's async:false, this property

The default is true: asynchronous, false: synchronous.

$.ajax({

Type: "post",

Url: "path",

Cache:false,

Async:false,

dataType: ($.browser.msie) ? "text" : "xml",

Success: funcTIon(xmlobj){

}

});

With this property, you can relatively reduce the code running book order problem, but if you use too much, the page has too many fake deaths. This in turn leads to poor user experience~!

The official explanation for async and success in $.Ajax():

Async

Boolean

Default: true

By default, all requests are sent asynchronous (eg this is set to true by default). If you need synchronous requests, set this opTIon to false. Note that synchronous requests may temporarily lock the browser, disabling any acTIons while the request is acTIve.

Success

Function

A function to be called if the request succeeds. The function gets passed two arguments: The data returned from the server, formatted according to the 'dataType' parameter, and a string describing the status. This is an Ajax Event.

Here, the default setting of async is true. This is asynchronous. That is to say, when ajax sends a request, in the process of waiting for the server to return, the foreground will continue to execute the script behind the ajax block until the server returns. The correct result will be executed by success, which means that two threads are executed at this time. The script after the ajax block issues the request and the script behind the ajax block (another thread):

$.ajax({

Type: "POST",

Url: "Venue.aspx?act=init",

dataType: "html",

Success:function(result){ //function1()

F1();

F2();

}

Failure:function (result) {

Alert('Failed');

},

}

Function2();

In the above example, when the ajax block makes a request, it will stop function1() and wait for the server to return, but at the same time (during this waiting process), the foreground will execute function2(), that is, at this time. Two threads, we will temporarily say here as function1() and function2().

When asyn is set to false, then the ajax request is synchronized, that is, after this time the ajax block makes a request, it will wait in the function1 () this place, will not execute function2 (), know function1 ( Partial execution is completed.

I always thought that just synchronization is fine. In fact, if you synchronize, you lose the meaning of ajax.

Encountered a bug.

The page is loaded and loaded. . . . . Reference a publish.js

1 function loader(m) {

2 var left = (window.innerWidth / 2) - 83;

3 var top = window.innerHeight / 2 - 60;

4 var height = 50;

5 var html =

6 '"div id="ajaxloader_zz" style=“z-index: 9999998; position: absolute; top: 0px; left: 0; width: 100%; height: 100%; opacity: 0; ””/div ' +

7 '"div id="ajaxloader" style="width:200px;height:100px; text-align:center;background-color:snow;border-radius:5px; position:fixed;top:' + top + 'px ;left:' + left + 'px;z-index:9999999;""' +

8 '"table style="vertical-align:middle;text-align:center; width:100%;height:100%;""' +

9 'tr>td》div style=“margin-top:20px;””“img src=”./images/loading.gif” /”//div”/td”/tr” +

10 'tr>td》span style=“color:black;font-family:Helvetica-Regular;font-weight:bold;font-size:16px””' + m + '/span》/td "/tr" "/table" "/div"';

11 return html;

12 }

13

14 //Request to start animation

15 $(document).ajaxSend(function () {

16 alert(1);

17 if ($("#ajaxloader").length == 0) {

18 $("body").append(loader("Please wait..."));

19 $("#ajaxloader,#ajaxloader_zz").fadeIn("normal");

20 }

twenty one });

twenty two

23 //// request success animation

24 $(document).ajaxSuccess(function () {

25 if ($("#ajaxloader").length 》 0) {

26 $("#ajaxloader,#ajaxloader_zz").fadeOut("normal");

27 $("#ajaxloader,#ajaxloader_zz").remove();

28 }

29 });

30 //Request error animation

31 $(document).ajaxError(function () {

32 if ($("#ajaxloader").length 》 0) {

33 $("#ajaxloader,#ajaxloader_zz").fadeOut("normal");

34 $("#ajaxloader,#ajaxloader_zz").remove();

35 $("body").append(loader("Request failed!"));

36 $("#ajaxloader,#ajaxloader_zz").fadeIn("normal");

37 setTimeout(function () { $("#ajaxloader,#ajaxloader_zz").fadeOut("normal"); $("#ajaxloader,#ajaxloader_zz").remove(); }, 1000);

38 }

39 });

The page references this js. When there is an ajax operation, there will be a wait. . . . Tip

If the ajax request used in the page is synchronous. This effect won't work on browsers like google and ie. Change to asynchronous.

Note: Add async:false. It is modified to be synchronized. What do you mean? (According to the colleague's explanation, this is to wait for the ajax to have the return value before executing the following js. In a word, it is no wonder that many assignments in the previous ajax call do not work). After the ajax assigns the value to the bol, the following js part is executed. And just asynchronous, if you haven't had time to assign, you have already returned.

Camera Pen

Many people do not know what kind of cameras are invisible cameras, and do not know how to distinguish invisible cameras, so here is how to distinguish invisible cameras.
Invisibility, as the name suggests, means that it is not easy to be seen or found, so where do such cameras exist? In fact, invisible things are hidden by the external environment, so they will not be discovered. Such invisible cameras are generally hidden in things that are more difficult to see, such as: inside the socket, inside the TV, inside the stereo, inside the fan, etc. Cameras can be hidden in various household appliances. Why should they be hidden in electrical equipment? The main reason is that these equipments have power supply and will not be used because the camera cannot be powered.

Camera Pen,the memory reaches 32G,easy to carry camera,Hidden Camera HD1080p,Hidden Camera HD720P

Jingjiang Gisen Technology Co.,Ltd , https://www.gisengroup.com