jqmodal提交表单ajax——如何重置
好的,我搜索了,但没有提出我的确切问题...
我加载一个带有隐藏 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
希望您现在已经找到并回答了:) 我最近在 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.