weixin_33697898 2017-04-18 07:35 采纳率: 0%
浏览 4

循环内的Ajax调用

I have a loop in my jQuery code. Inside the loop there is an AJAX call. Since for each loop an AJAX call to the server is fired, does it mean a new thread is created for each call at the server side? Do all calls get a new thread? This is my jQuery code for your reference:

function Run() {
  var i = 0;
  var r = '${result}'
  var par = '${paramy}'
  var str = r.replace(/?
|/g, " ");
  var resjson = JSON.parse(str);
  var parjson = JSON.parse(par);

  //loop to send ajax req multiple times. 
  for (var i = 0; i < resjson.length; i++) {
    var k = i + 1;
    var m = encodeURIComponent(JSON.stringify(resjson[i]));
    var py = encodeURIComponent(JSON.stringify(parjson));
    var pass = '';

    $.ajax({
      type: 'post', // it's easier to read GET request parameters
      url: 'servlet1',
      async: true,
      data: { 
        r: m,
        p:py
      },
      success: function(data) {
        console.log("pass"`enter code here`)
      },
      error: function(data) {
        console.log("fail"); 
      }
    });
  }
}
  • 写回答

2条回答 默认 最新

  • weixin_33697898 2017-04-18 07:53
    关注

    Since for each loop an AJAX call to the server is fired, does it mean a new thread is created for each call at the server side?

    That depends entirely on the infrastructure being used on the server side. Few servers would create a brand-new thread for each request but many would assign a thread from a pool to each request, and return that thread to the pool when the request is serviced.

    评论

报告相同问题?