title: ajax success redirect to another page before completing request
body: <p>I have multiple request going from client to server using Ajax. Once all requests are completed , I am sending success message to Ajax success function and then redirecting to different page. but before completing all requests , it get redirected to different page. How to resolve it</p>
  
  <p>Ajax Call </p>
  
  <pre><code> $(document).ready(function () {
         $('#btnCreateProg').click(function (e) {
             //alert("hi");
             //debugger;
             //var state = $('#listBoxFormState option:selected').val();
             var states = $.map($('#listBoxFormState option:selected'), function (element) {
                 return element.value;
             });
             var checkedboxCount = $("input:checked").length;
  
             $('input[type=checkbox]:checked').each(function (i, ob) {
                 //alert($(ob).val());
                 var msType = $(ob).val();
                 // debugger;
                 var NBEffDate = $("#NBEffDate").datepicker().val();
                 var RenEffDate = $("#RenEffDate").datepicker().val();
                 //debugger;
                 jQuery.ajax({
                     type: "POST",
                     url: "AccelatorUI.aspx/CreateManuscript",
                     data: JSON.stringify({ "manuscriptType": msType, "nbEffDate": NBEffDate.toString(), "renEffDate": RenEffDate.toString(), "states": states, "checkedboxCount": checkedboxCount }),
                     contentType: "application/json; charset=utf-8",
                     dataType: "json",
                     success: function (response) {
  
                         //debugger;
                                                    if (response.d = "success") {
                                                        window.location = "Summary.aspx";
                                                    }
                         //debugger;
                        // window.location = response.d;
                     },
  
                     error: function (xhr, status, error) {
                         alert('Failed :' + xhr.status + xhr.statusText + xhr.readyState + xhr.responseText + error);
                     }
                 });
             });
         });
  </code></pre>
  
  <p>Server Side ( c# code ) </p>
  
  <pre><code> [WebMethod]
      public  static string CreateManuscript(string manuscriptType ,string nbEffDate ,string renEffDate ,List&lt;string&gt; states ,string checkedboxCount)
      {
          string response = string.Empty;
  
          try
          {
  
              response = "";
              DTO.ManuscriptInfo msInfo = new DTO.ManuscriptInfo();
              DTO.ManuscriptCatlog msCatlog = new DTO.ManuscriptCatlog();
  
              msInfo.NewBusinessEffDate = nbEffDate;
              msInfo.RenewEffDate = renEffDate;
              msInfo.DCTResponseXML = HttpContext.Current.Session["dctResponseXML"].ToString();
              string catlogFile = ConfigurationManager.AppSettings["catlogPath"];
  
  
              msInfo.GenerateManuscriptID(manuscriptType);
              HttpContext.Current.Session["count"] = Int32.Parse(HttpContext.Current.Session["count"].ToString()) + 1;
  
              msInfo.GetInheritedManuscriptID();
              msInfo.GetVersionIDforCatlog();
  
              //foreach ( string state in states )
              //{
  
  
               msInfo.CreateManuscript();
  
               msInfo.SetManuscriptProperties();
               msInfo.CreateFolderStructure();
             // }
              //Response.Redirect("Summary.aspx");
  
  
  
              msCatlog.RandomManuscriptID = msInfo.RandomManuscriptID;
              catlogDataPair.Add(new KeyValuePair&lt;string, string&gt;(manuscriptType, msInfo.RandomManuscriptID));
              msCatlog.ManuscriptID = msInfo.ManuscriptID;
              catlogDataPair.Add(new KeyValuePair&lt;string, string&gt;(manuscriptType, msInfo.ManuscriptID));
  
              msCatlog.NewManuscriptPath = msInfo.NewManuscriptPath;
              catlogDataPair.Add(new KeyValuePair&lt;string, string&gt;(manuscriptType, msInfo.NewManuscriptPath));
              msCatlog.VersionID = msInfo.VersionID;
              catlogDataPair.Add(new KeyValuePair&lt;string, string&gt;(manuscriptType, msInfo.VersionID));
  
              manuscriptTypeList.Add(manuscriptType);
  
              List&lt;string&gt; li = new List&lt;string&gt;();
  
              if (HttpContext.Current.Session["count"].ToString() == checkedboxCount)
              {
                  foreach (var msItem in manuscriptTypeList)
                  {
                      foreach (var item in catlogDataPair)
                      {
                          if (item.Key == msItem)
                          {
                              li.Add(item.Value);
                          }
                      }
  
                      msCatlog.RandomManuscriptID = li[0];
                      msCatlog.ManuscriptID = li[1];
                      msCatlog.NewManuscriptPath = li[2];
                      msCatlog.VersionID = li[3];
                      msCatlog.CompanyName = msInfo.CompanyName;
                      msCatlog.UpdateManuscriptCatlog();
                      li = new List&lt;string&gt;();
                  }
  
                  response = "success";
  
              }
          }
  
          catch (Exception ex)
          {
              System.Diagnostics.Trace.WriteLine(" Exception occurred in static CreateManuscript Method " + ex.Message + ex.StackTrace);
          }
  
  
           return response;
      }
  </code></pre>