【发布时间】:2012-07-10 18:54:49
【问题描述】:
假设我在add-project.html 页面上有一个表单。请求完成后,我将用户重定向回主 index.html 页面。
我想要做的是在用户成功提交表单后仅在index.html 上显示通知。
我正在使用这个插件来通知:http://redeyeoperations.com/plugins/Notify/
目前,我正在使用一个临时解决方案,它在提交表单时在add-project.html 上显示通知,然后在setTimeout 之后重定向到index.html 主页面,但我不喜欢它,它是很脏。
$('#printForm').submit(function(e) {
e.preventDefault();
$.ajax({
type: 'POST',
url: 'add-project.php',
data: $('#printForm').serialize(),
success: function(result) {
if(result == '1') {
// Success
$.notify.basic('Congratulations, your projet has been saved correctly', {
occupySpace : true,
close : true,
autoClose: 5000
});
setTimeout(function() {
window.location.href = '../index.html';
}, 2000);
}
else {
// Error
$.notify.error('Oops, something went wrong ! Make sure you filled all the necessary fields', {
occupySpace : true,
close : true,
autoClose: 5000
});
}
}
});
});
有没有一种干净的方法可以在重定向后在目标页面上显示通知?
感谢您的帮助。
【问题讨论】:
-
你为什么不尝试使用 ajaxLoad ?
标签: jquery ajax redirect notifications