jqmodal提交表单ajax——如何重置

发布于 2024-12-26 01:15:56 字数 942 浏览 1 评论 0原文

好的,我搜索了,但没有提出我的确切问题...

我加载一个带有隐藏 div 的 jqModal,其中包含一个联系表单,该表单通过 $.ajax 发布到处理页面 一切正常。响应消息显示在模式框中,然后用户可以退出模式。

问题是当重新触发模态获取时(没有父页面刷新),它会显示上次使用模态的响应文本。我想用空白表单重新加载父页面上的隐藏 div。

$('.submitModal').click(function(e){
   e.preventDefault();
   $('form').hide(); 
   var pStartTime = $('#eventStartTime').val();
   var eventDataString = 'startTime='+pStartTime;
   $.ajax({
      type:"POST",
      url:"i_calendarAddEvent.php",
      data:eventDataString,
      success: function(responseText){
         $('.addEventTitle').html('Success. Event Added.');
         $('.showResponse').html(responseText);
      }
   });
});

我尝试添加一个调用来重置表单元素(在 $.ajax success 函数中),但不确定它是否有效,因为隐藏 div 中的表单再也不会显示。

function resetForm(formid) {
    $('#' + formid + ' :input').each(function(){ 
        $(this).val('').attr('checked',false).attr('selected',false);
    });
}

感谢您的任何见解。

Ok, I searched, but didn't come up with my exact issue...

I load a jqModal with a hidden div that contains a contact form which posts to process page via $.ajax
All works fine. The response message displays in the modal box and user can then exit out of modal.

The issue is when the modal get's re-triggered (without a parent page refresh), it displays the response text from the previous usage of the modal. I'd like to reload the hidden div on the parent page with the blank form.

$('.submitModal').click(function(e){
   e.preventDefault();
   $('form').hide(); 
   var pStartTime = $('#eventStartTime').val();
   var eventDataString = 'startTime='+pStartTime;
   $.ajax({
      type:"POST",
      url:"i_calendarAddEvent.php",
      data:eventDataString,
      success: function(responseText){
         $('.addEventTitle').html('Success. Event Added.');
         $('.showResponse').html(responseText);
      }
   });
});

I've tried adding a call to reset the form elements (in the $.ajax success function), but not sure if it works because the form in the hidden div never shows again.

function resetForm(formid) {
    $('#' + formid + ' :input').each(function(){ 
        $(this).val('').attr('checked',false).attr('selected',false);
    });
}

Thanks for any insights.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离笑几人歌 2025-01-02 01:15:56

希望您现在已经找到并回答了:) 我最近在 ajax 帖子中遇到了类似的问题。基本上发生的事情是 ajax 请求被缓存。我的解决方案是将

$.ajaxSetup({ cache: false });

添加到我的脚本文件中。让我知道它是否适合您的情况。

Hopefully you have found and answer by now :) I recently ran in to a similar problem with an ajax post. Basically what was happening is that the ajax request was being cached. My solution was to add

$.ajaxSetup({ cache: false });

to my script file. Let me know if it works for your situation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文