使用ajax发布表单,然后刷新整个表单 [英] Post the form using ajax and then refresh the whole form

查看:76
本文介绍了使用ajax发布表单,然后刷新整个表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我,使用ajax发布表单,然后刷新整个表单,

i我使用下面的ajax方法将表单发布到控制器,然后在控制器方法中保存数据并将去

重定向动作方法重新加载表单,我如何获得返回成功消息,下面是我的代码



视图中的代码

尝试{

var data = new FormData(this.form);

$ .ajax({

url :/ CreateApplicationFromSearch / SaveAndCloseApplication,//注意:使用正确的操作名称

类型:POST,

数据:数据,

processData:false,

contentType:false,

成功:函数(响应){

if(response!= null&& response.success){

var ApplicantId =(response.Applicant_id);

var ApplicationId =(response.Application_id);

ModalDialogue(ApplicantId ,ApplicationId);

alert(response.responseText);

}

},

错误:功能(响应){

alert(error!+ response.responseText);

}

});

} catch(ex){alert(ex);控制器中的
代码

[HttpPost]

public ActionResult SaveApplication(tr_applications Application,string OfficeHolder_id, ?INT AccountDetail_Id,串contact_person_id,IEnumerable的< httppostedfilebase> specific_Item,IEnumerable的< httppostedfilebase> Position_Description,IEnumerable的< httppostedfilebase> Employment_Contract,IEnumerable的< httppostedfilebase> Invoices_PhonePower,IEnumerable的< httppostedfilebase> Lease_Rent,

的IEnumerable< httppostedfilebase> Travel_Itinerary ,IEnumerable< httppostedfilebase> Members_Travelling,

IEnumerable< httppostedfilebase> not_profitletter,IEnumerable< httppostedfilebase> ; schoolletter,IEnumerable< httppostedfilebase> affiliatedletter,

I枚举< httppostedfilebase> finanncialstatement,IEnumerable< httppostedfilebase>银行验证)

{

service.SaveApplication(Application,specific_Item,Position_Description,

Employment_Contract,Invoices_PhonePower,Lease_Rent,Travel_Itinerary,

Members_Travelling,Capital_Works,Covering_Letter,Resolution_ToApply,

not_profitletter,schoolletter,affiliatedletter,finanncialstatement,bankverification,

applicant_id,Applicant_Name);



if(OfficeHolder_id!=)

Applicant_Service.Update_ApplicationId_OfficeHolder(OfficeHolder_id,Application.application_id);



if(AccountDetail_Id!= null&& AccountDetail_Id!= 0)

Applicant_Service.Update_Account_ApplicantionId(Convert.ToInt32(AccountDetail_Id),Application.application_id);



if(contact_person_id!=)

Applicant_Service.Update_ApplicationID_Contacts(contact_person_id,Application.application_id);



返回RedirectToAction(EditApplication,new {Application.applicant_id,Application.application_id,OfficeHolder_id,AccountDetail_Id,contact_person_id });

}



我尝试了什么:



视图中的代码

尝试{

var data = new FormData(this.form);

$ .ajax( {

url:/ CreateApplicationFromSearch / SaveAndCloseApplication,//注意:使用正确的操作名称

类型:POST,

数据:data,

processData:false,

contentType:false,

成功:函数(响应){

if(响应!= null&& response.success){

var ApplicantId =(response.Applicant_id);

var ApplicationId =(response.Application_id);

ModalDialogue(ApplicantId ,ApplicationId);

alert(response.responseText);

}

},

错误:function(响应){

alert(error!+ response.responseText);

}

});

} catch(ex){alert(ex); }

}

Hi can some one help me, post the form using ajax and then refresh the whole form ,
i am posting the form using below ajax method to controller, then in controller method save the data and will go the
redirect action method to reload the form and how can i get return success message in below is my code

code in view
try {
var data = new FormData(this.form);
$.ajax({
url: "/CreateApplicationFromSearch/SaveAndCloseApplication", // NB: Use the correct action name
type: "POST",
data: data,
processData: false,
contentType: false,
success: function (response) {
if (response != null && response.success) {
var ApplicantId = (response.Applicant_id);
var ApplicationId = (response.Application_id);
ModalDialogue(ApplicantId, ApplicationId);
alert(response.responseText);
}
},
error: function (response) {
alert("error!" + response.responseText);
}
});
} catch (ex) { alert(ex); }
}
code in controller
[HttpPost]
public ActionResult SaveApplication(tr_applications Application, string OfficeHolder_id, int? AccountDetail_Id, string contact_person_id, IEnumerable<httppostedfilebase>specific_Item, IEnumerable<httppostedfilebase> Position_Description, IEnumerable<httppostedfilebase> Employment_Contract,IEnumerable<httppostedfilebase> Invoices_PhonePower, IEnumerable<httppostedfilebase> Lease_Rent,
IEnumerable<httppostedfilebase> Travel_Itinerary, IEnumerable<httppostedfilebase> Members_Travelling,
IEnumerable<httppostedfilebase> Capital_Works, IEnumerable<httppostedfilebase> Covering_Letter, IEnumerable<httppostedfilebase> Resolution_ToApply,
IEnumerable<httppostedfilebase> not_profitletter, IEnumerable<httppostedfilebase> schoolletter, IEnumerable<httppostedfilebase> affiliatedletter,
IEnumerable<httppostedfilebase> finanncialstatement, IEnumerable<httppostedfilebase> bankverification)
{
service.SaveApplication(Application, specific_Item, Position_Description,
Employment_Contract, Invoices_PhonePower, Lease_Rent, Travel_Itinerary,
Members_Travelling, Capital_Works, Covering_Letter, Resolution_ToApply,
not_profitletter, schoolletter, affiliatedletter, finanncialstatement, bankverification,
applicant_id, Applicant_Name);

if (OfficeHolder_id != "")
Applicant_Service.Update_ApplicationId_OfficeHolder(OfficeHolder_id, Application.application_id);

if (AccountDetail_Id != null && AccountDetail_Id != 0)
Applicant_Service.Update_Account_ApplicantionId(Convert.ToInt32(AccountDetail_Id), Application.application_id);

if (contact_person_id != "")
Applicant_Service.Update_ApplicationID_Contacts(contact_person_id, Application.application_id);

return RedirectToAction("EditApplication", new { Application.applicant_id, Application.application_id, OfficeHolder_id, AccountDetail_Id, contact_person_id });
}

What I have tried:

code in view
try {
var data = new FormData(this.form);
$.ajax({
url: "/CreateApplicationFromSearch/SaveAndCloseApplication", // NB: Use the correct action name
type: "POST",
data: data,
processData: false,
contentType: false,
success: function (response) {
if (response != null && response.success) {
var ApplicantId = (response.Applicant_id);
var ApplicationId = (response.Application_id);
ModalDialogue(ApplicantId, ApplicationId);
alert(response.responseText);
}
},
error: function (response) {
alert("error!" + response.responseText);
}
});
} catch (ex) { alert(ex); }
}

推荐答案

.ajax({

url:/ CreateApplicationFromSearch / SaveAndCloseApplication,//注意:使用正确的操作名称

类型:POST,

数据:数据,

processData:false,

contentType:false,

成功:函数(响应){

if(response!= null&& response.success){

var ApplicantId =(response.Applicant_id);

var ApplicationId =(response.Application_id);

ModalDialogue(ApplicantId,ApplicationId);

alert(response.responseText);

}

},

错误:功能(响应){

alert(error!+ response.responseText);

}

});

} catch(ex){alert(ex) );控制器中的
代码

[HttpPost]

public ActionResult SaveApplication(tr_applications Application,string OfficeHolder_id, ?INT AccountDetail_Id,串contact_person_id,IEnumerable的< httppostedfilebase> specific_Item,IEnumerable的< httppostedfilebase> Position_Description,IEnumerable的< httppostedfilebase> Employment_Contract,IEnumerable的< httppostedfilebase> Invoices_PhonePower,IEnumerable的< httppostedfilebase> Lease_Rent,

的IEnumerable< httppostedfilebase> Travel_Itinerary ,IEnumerable< httppostedfilebase> Members_Travelling,

IEnumerable< httppostedfilebase> not_profitletter,IEnumerable< httppostedfilebase> ; schoolletter,IEnumerable< httppostedfilebase> affiliatedletter,

I枚举< httppostedfilebase> finanncialstatement,IEnumerable< httppostedfilebase>银行验证)

{

service.SaveApplication(Application,specific_Item,Position_Description,

Employment_Contract,Invoices_PhonePower,Lease_Rent,Travel_Itinerary,

Members_Travelling,Capital_Works,Covering_Letter,Resolution_ToApply,

not_profitletter,schoolletter,affiliatedletter,finanncialstatement,bankverification,

applicant_id,Applicant_Name);



if(OfficeHolder_id!=)

Applicant_Service.Update_ApplicationId_OfficeHolder(OfficeHolder_id,Application.application_id);



if(AccountDetail_Id!= null&& AccountDetail_Id!= 0)

Applicant_Service.Update_Account_ApplicantionId(Convert.ToInt32(AccountDetail_Id),Application.application_id);



if(contact_person_id!=)

Applicant_Service.Update_ApplicationID_Contacts(contact_person_id,Application.application_id);



返回RedirectToAction(EditApplication,new {Application.applicant_id,Application.application_id,OfficeHolder_id,AccountDetail_Id,contact_person_id });

}



我尝试了什么:



视图中的代码

try {

var data = new FormData(this.form);
.ajax({
url: "/CreateApplicationFromSearch/SaveAndCloseApplication", // NB: Use the correct action name
type: "POST",
data: data,
processData: false,
contentType: false,
success: function (response) {
if (response != null && response.success) {
var ApplicantId = (response.Applicant_id);
var ApplicationId = (response.Application_id);
ModalDialogue(ApplicantId, ApplicationId);
alert(response.responseText);
}
},
error: function (response) {
alert("error!" + response.responseText);
}
});
} catch (ex) { alert(ex); }
}
code in controller
[HttpPost]
public ActionResult SaveApplication(tr_applications Application, string OfficeHolder_id, int? AccountDetail_Id, string contact_person_id, IEnumerable<httppostedfilebase>specific_Item, IEnumerable<httppostedfilebase> Position_Description, IEnumerable<httppostedfilebase> Employment_Contract,IEnumerable<httppostedfilebase> Invoices_PhonePower, IEnumerable<httppostedfilebase> Lease_Rent,
IEnumerable<httppostedfilebase> Travel_Itinerary, IEnumerable<httppostedfilebase> Members_Travelling,
IEnumerable<httppostedfilebase> Capital_Works, IEnumerable<httppostedfilebase> Covering_Letter, IEnumerable<httppostedfilebase> Resolution_ToApply,
IEnumerable<httppostedfilebase> not_profitletter, IEnumerable<httppostedfilebase> schoolletter, IEnumerable<httppostedfilebase> affiliatedletter,
IEnumerable<httppostedfilebase> finanncialstatement, IEnumerable<httppostedfilebase> bankverification)
{
service.SaveApplication(Application, specific_Item, Position_Description,
Employment_Contract, Invoices_PhonePower, Lease_Rent, Travel_Itinerary,
Members_Travelling, Capital_Works, Covering_Letter, Resolution_ToApply,
not_profitletter, schoolletter, affiliatedletter, finanncialstatement, bankverification,
applicant_id, Applicant_Name);

if (OfficeHolder_id != "")
Applicant_Service.Update_ApplicationId_OfficeHolder(OfficeHolder_id, Application.application_id);

if (AccountDetail_Id != null && AccountDetail_Id != 0)
Applicant_Service.Update_Account_ApplicantionId(Convert.ToInt32(AccountDetail_Id), Application.application_id);

if (contact_person_id != "")
Applicant_Service.Update_ApplicationID_Contacts(contact_person_id, Application.application_id);

return RedirectToAction("EditApplication", new { Application.applicant_id, Application.application_id, OfficeHolder_id, AccountDetail_Id, contact_person_id });
}

What I have tried:

code in view
try {
var data = new FormData(this.form);


.ajax({

url:/ CreateApplicationFromSearch / SaveAndCloseApplication,// NB:使用正确的操作名称

类型:POST,

数据:数据,

processData:false,

contentType:false,

成功:函数(响应){

if(response!= null&& response.success){

var ApplicantId =(response.Applicant_id);

var ApplicationId =(response.Application_id);

ModalDialogue(ApplicantId ,ApplicationId);

alert(response.responseText);

}

},

错误:function(响应){

alert(error!+ response.responseText);

}

});

} catch(ex){alert(ex); }

}
.ajax({
url: "/CreateApplicationFromSearch/SaveAndCloseApplication", // NB: Use the correct action name
type: "POST",
data: data,
processData: false,
contentType: false,
success: function (response) {
if (response != null && response.success) {
var ApplicantId = (response.Applicant_id);
var ApplicationId = (response.Application_id);
ModalDialogue(ApplicantId, ApplicationId);
alert(response.responseText);
}
},
error: function (response) {
alert("error!" + response.responseText);
}
});
} catch (ex) { alert(ex); }
}


这篇关于使用ajax发布表单,然后刷新整个表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆