Problem description
In the front-end development, we found a request that took a long time to process and never returned data. Browser development tool – Network – request interface report red after positioning problems found that Ajax request encountered a long time to load over a certain period of time will directly interrupt the request
The solution
Check if timeout is set in the Ajax request configuration in your code. If there is an interface in the requirement that takes a long time to process the request, it is recommended to remove this or to set a suitable time and set a user prompt for timeout in the timeout callback
ajax({ url: url, type:'POST', data: data, async: async, contentType: "application/json; Charset = utf-8 ", traditional: true, timeout: 30000, // request timeout... })
conclusion
This article describes the problem of interrupting requests when the timeout property is set in Ajax and how to solve it. It is not enough to only realize business requirements in daily development. We need to test the performance of web pages in extreme network environment and solve problems to keep the code robust, otherwise it will become problems online and be discovered by users. Check out my other articles on Ajax requests.