简体   繁体   中英

How to regulate sending requests to server?

I need to send many requests to server 50-100 requests to load data, each response has at least 0.5KB and at most 7KB of data.

I send the requests using ajax as following: (code is simplified)

for (var i=0; i<elements.length; i++) {
    var element = elements[i];
    // make ajax call with element as parameter and update page to show data for element
}

This works for my needs, because I dont need data to come from server in order, and it works most of the time. But sometimes the last few elements dont get loaded and I get communication link failure error in my chrome javascript console.

I am assuming that the server got overloaded, how can I regulate sending requests to make sure I get a response for each request in the shortest time possible?

Notes:

  • I use Spring MVC in the backend
  • I use ExtJS Ajax to make the requests

Try using seperate loops for your data uploading process. Overloading is the only cause for that Communication failure.

我通过递归调用每个请求来解决此问题,这样,此时仅将一个请求发送到服务器,并且避免了过载。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM