Javascript 使用单个响应处理程序处理来自后端web服务的多个web请求响应

Javascript 使用单个响应处理程序处理来自后端web服务的多个web请求响应,javascript,ajax,asynchronous,Javascript,Ajax,Asynchronous,因此,我有以下代码,它使用相同的服务向后端的asp.net Web服务发送一组请求。方法相同,只是每次数据都不同,它们在for循环中发送: for (let i = 1; i <= totalNumberOfDataRows; i++) { //some code //service,method are the same below, just body is different within each loop app.sendToService(service, method, bo

因此,我有以下代码,它使用相同的服务向后端的asp.net Web服务发送一组请求。方法相同,只是每次数据都不同,它们在for循环中发送:

for (let i = 1; i <= totalNumberOfDataRows; i++) {
//some code
//service,method are the same below, just body is different within each loop
app.sendToService(service, method, body, this._handleResponse.bind(this)
}
问题是,这个响应处理程序一次只能处理来自后端的一个响应。我现在编写代码的方式是,一旦来自for循环的任何调用的任何响应返回,就会调用响应处理程序,它就会中断,从而使它无法处理任何响应(如果有另一个响应返回)

我如何更改
\u handleResponse
方法来修复此情况,使其等待此方法的所有响应都停止,以脱离
'case'

_handleResponse: function(response, body, method) {

   var data = response.d.result;
        switch (method) {
          //some code with case/break with other methods
          default:
            if (response.d.statusCode === 0) {
              app.showDialog("Definitions", "Successfully updated.");
              this._requestData(this.routeData.guid);
            } else {
              //2/18/2019: added error message to display
              app.showDialog("Definitions (FAILED)", "Failed to update. " + response.d.statusMsg);
            }
            break;
        }
   }