2

I m trying to update bulk of data one by one using Jquery ajax,so that i can show update progress. every thing goes well at beginning but after 5 min, it throw an error like in Image while checking network request/respond:.

network error

Error on error function of ajax:.

enter image description here

MainData is array of json object and is contain around 3000 number of json object.

function DoPost()
   {
       $.each(MainData, function (key, value) {
          var mainCode = value.MainCode;
          var companyCode = value.CompanyCode;
          $.ajax({
              url: "Allotment.asmx/DoAllotment",
              data: "{MainCode:'" + mainCode + "', sNoOfAllotment:'" + noOfAllot + "',CompanyCode:'" + companyCode + "'}",
              dataType: 'text',
              contentType: "application/json; charset=utf-8",
              type: "Post",
              success: function (res){
                   Progress(res);   // this funtion will show progress of update.
               },
               error: function (res) {
                   console.log(res);
               }
           });
       });
    }

I am using web service of asp.net webform

2 Answers2

0

The issue could be maximum number of concurrent connections to same URL. You can schedule next $.ajax() call when current $.ajax() completes.

See also multiple, sequential fetch() Promise

function DoPost(value) {
  var mainCode = value.MainCode;
  var companyCode = value.CompanyCode;
  return $.ajax({
    url: "Allotment.asmx/DoAllotment",
    data: "{MainCode:'" + mainCode + "', sNoOfAllotment:'" 
           + noOfAllot + "',CompanyCode:'" + companyCode + "'}",
    dataType: 'text',
    contentType: "application/json; charset=utf-8",
    type: "POST",
    success: function(res) {
      Progress(res); // this funtion will show progress of update.
    },
    error: function(res) {
      console.log(res);
    }
  });
}

var copy = MainData.slice(0);
var res = (function re(value) {
  return DoPost(value).then(function() {
    return copy.length ? re(copy.shift()) : "complete"
  })
})(copy.shift());

res.then(function(complete) {
  console.log(complete)
}, function(err, textStatus, jqxhr) {
  console.log(err)
});
Community
  • 1
  • 1
guest271314
  • 1
  • 15
  • 104
  • 177
  • Promises in javascript is totally new for me. Sir could you please explain a bit more, how this code works. – rajiv shrestha Feb 14 '17 at 09:32
  • The pattern creates a copy of the original array, in case original array needs to be preserved at `copy`, then calls `$.ajax()` request in sequential order, making next request when previous request completes. You could alternatively post `MainData` at one `POST` request, given explanation of issue by @TariqB. – guest271314 Feb 14 '17 at 18:23
0

The error 0x2ee2 is IE's representation of timeout error. The occurrence of this error shows that the server has stopped responding to the requests due to a high number of requests sent from the same client. This is the server avoiding DOS attacks from the client.

The proper method is to optimize the code and try to utilize the maximum available bandwidth in order to minimize the number of requests to the server.

Tariq B.
  • 553
  • 3
  • 11