我试图在成功的 ajax 调用后显示确认消息。用户单击链接以向另一个用户发送消息,这会打开一个对话框。他们发送消息后,我隐藏表单并显示一条简单的消息,例如“已发送消息”。但是,在用户关闭对话框并重新打开后,表单不会重新出现并且消息仍然存在。
这是弹出对话框和消息表单:
<a href="#MessageStudent" class="popUpLink">Message</a>
<div class="popUpDialog" id="messageStudentDialog">
<div id="messageStatus"></div>
<form class="sendMessageForm" id="studentForm" action="" method="POST">
<fieldset>
<input type="hidden" value="317" name="studentID">
<textarea rows="3" cols="35" name="message"></textarea>
<input type="submit" value="Send Message">
</fieldset>
</form>
</div>
这是用于单击链接和对话框的 jQuery 处理程序:
function popUpDialogs()
{
$('.popUpLink').each(function()
{
if(!$.data(this, 'dialog'))
{
$divDialog = $(this).next('.popUpDialog');
$.data(this, 'dialog', $divDialog.dialog(
{
autoOpen: false,
modal: true,
title: $divDialog.attr('title')
}));
}
}).on('click',function()
{
$.data(this, 'dialog').dialog('open');
$('form',$divDialog).toggle(); //This is what I'm trying but doesn't work
return false;
});
}
这是我的 AJAX 表单处理程序:
$('form.sendMessageForm', '.popUpDialog').on('submit', function()
{
event.preventDefault();
var form = $(this);
var popUpDialog = form.parent();
var data = new Array();
var data = form.serialize();
$.post('', { sendMessage : data}, function(response)
{
$(form).toggle();//This is what I'm trying but it doesn't work
$('div#messageStatus', popUpDialog).html("<p>Message Sent!</p>").hide().fadeIn(3000).animate({opacity: 1.0}, 3000) //<== wait 3 sec before fading out
.fadeOut('slow', function()
{
});
});
});
任何帮助,将不胜感激!谢谢!