我有多个请求使用Ajax从客户端发送到服务器。完成所有请求后,我将成功消息发送到Ajax成功函数,然后重定向到不同的页面。但在完成所有请求之前,它会被重定向到不同的页面。如何解决它
Ajax Call
$(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);
}
});
});
});
服务器端(c#代码)
[WebMethod]
public static string CreateManuscript(string manuscriptType ,string nbEffDate ,string renEffDate ,List<string> 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<string, string>(manuscriptType, msInfo.RandomManuscriptID));
msCatlog.ManuscriptID = msInfo.ManuscriptID;
catlogDataPair.Add(new KeyValuePair<string, string>(manuscriptType, msInfo.ManuscriptID));
msCatlog.NewManuscriptPath = msInfo.NewManuscriptPath;
catlogDataPair.Add(new KeyValuePair<string, string>(manuscriptType, msInfo.NewManuscriptPath));
msCatlog.VersionID = msInfo.VersionID;
catlogDataPair.Add(new KeyValuePair<string, string>(manuscriptType, msInfo.VersionID));
manuscriptTypeList.Add(manuscriptType);
List<string> li = new List<string>();
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<string>();
}
response = "success";
}
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(" Exception occurred in static CreateManuscript Method " + ex.Message + ex.StackTrace);
}
return response;
}