问题描述
我的javascript文件中有以下jquery方法,该方法调用.submit()
方法提交表单:
I have the following jquery method in my javascript file which calls .submit()
method to submit a form:
var actionOfForm = $("#custom_targeting_param_form").attr('action');
actionOfForm = actionOfForm.replace('#export','');
actionOfForm = actionOfForm+'#export';
$("#custom_targeting_param_form").attr('action',actionOfForm);
try{
$("#custom_targeting_param_form").submit();
$("#showOrExportCustomTargetingReport").val('saveReport');
alert('Report Saved Successfully');
}catch(e){
//alert("ERROR OCCURRED :: "+e);
}
现在我要提醒的是成功提交"custom_targeting_param_form"消息您的表单已成功提交".
Now what I want is to alert a message "Your form has been submitted successfully" on the successful submission of "custom_targeting_param_form".
由于我在此处使用了警报,因此警报发生在实际提交之前.请帮忙.
As I have used the alert here, it happens prior to the actual submission.Please help.
推荐答案
异步提交表单以显示确认警报或从服务器端呈现启动js的警报提示消息.
Submit the form asynchronously in order to show a confirmation alert or render a startup js from the server side which will alert the confirmation message.
代码以异步方式提交表单
Code to submit the form asynchronously
$(function(){
$("#custom_targeting_param_form").submit(function(e){
e.preventDefault();//to stop the default form submit
var actionOfForm = $("#custom_targeting_param_form").attr('action');
actionOfForm = actionOfForm.replace('#export','');
actionOfForm = actionOfForm+'#export';
$("#showOrExportCustomTargetingReport").val('saveReport');
$.ajax({
url: actionOfForm,
type: $(this).attr("method"),
data: $(this).serialize(),
success: function(){
alert('Report Saved Successfully');
},
error: function(){
alert('Report Saving Failed. Please try again later');
}
});
});
这篇关于在成功提交表单时显示警报消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!