在成功提交表单时显示警报消息

编程入门 行业动态 更新时间:2024-10-24 01:56:35
本文介绍了在成功提交表单时显示警报消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的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'); } }); });

更多推荐

在成功提交表单时显示警报消息

本文发布于:2023-11-27 21:03:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639594.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:警报   表单   消息

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!