Ilj*_*lja 15 ajax jquery reload
现在我有一个用户输入信息的表单.它是处理bu jQuery ajax函数并设置为return false;
在用户提交表单后不会发生页面重新加载.虽然我需要重新加载页面,但如果我删除return false;
它会在显示成功消息之前刷新页面(此消息在用户提交数据后显示).
$.ajax({
type: "POST",
url: "scripts/process.php",
data: dataString,
success: function() {
$("#st_message").html("<p> Your article was successfully added!</p>");
//I need to reload page after the above message is shown
}
});
return false;
Run Code Online (Sandbox Code Playgroud)
因此,如何在显示<p> Your article was successfully added!</p>
消息后重新加载页面,稍有延迟,比如2 - 3秒,这样用户就可以实际读取消息了.
Rio*_*ams 31
您可以使用该setTimeout()
功能添加延迟,例如:
// This will reload the page after a delay of 3 seconds
window.setTimeout(function(){location.reload()},3000)
Run Code Online (Sandbox Code Playgroud)
满足您的需求:
$.ajax({
type: "POST",
url: "scripts/process.php",
data: dataString,
success: function() {
$("#st_message").html("<p> Your article was successfully added!</p>");
window.setTimeout(function(){location.reload()},3000)
}
});
return false;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
45754 次 |
最近记录: |