About ajax request access, such as problems that occur when the network is unstable

In the development process, sometimes there is a need to periodically request some data from the server. Because there are some problems in the use process today, it is specially written as a pit-filling record.

When you need to use a timed request server, such as using jquery's ajax, you must be careful to use async: false, because when this parameter is used in the development process, the browser will be locked, and it is only valid when waiting for the request to have a return value. Therefore, using this method in an unstable network state will cause the browser to lock for a long time, unable to operate, and may become unresponsive. Chrome will pop up a prompt to close or wait.

Therefore, you must pay attention to the use of async:false in the process of use.

Another problem is that when ajax is requested regularly, the next request may be executed before the previous request is completed. When the request is asynchronous, the problem of returning the order in reverse may occur, which may not be the result we want. , you can use adding a variable flag to change the method request identifier. If the previous request has not been completed (regardless of success or failure), the newly incoming program ends and waits for the next request.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325464249&siteId=291194637