成功提交表单时显示警告消息
我在我的javascript文件中有以下jquery方法,它调用.submit()
方法来提交表单:
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”时提醒“您的表单已成功提交”。
正如我在此处使用警报一样,它在实际提交之前发生。 请帮忙。
异步提交表单以显示确认警报或从服务器端呈现启动js,这将提醒确认消息。
用于异步提交表单的代码
$(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'); } }); });
使用带有回调的jQuery ajax()方法。