我有一些 jQuery 代码可以在数据库中插入记录。我需要在一段时间内重新加载页面。这意味着,当我点击提交按钮时,首先会显示成功消息或错误消息,然后在 5 秒后重新加载页面。
我的代码:
(function($){
$(document).ready(function(){
$("#submit").click(function(){
//alert("testing2.....")
var num = /^[0-9]/;
var date=$("#date").val();//alert(date);
var sMan=$("#sMan").val();//alert(pType);
var cName=$("#cName").val();
var input_type=$("#input_type").val();
var tamt=$("#tamt").val();
var tpaid=$("#tpaid").val();
//use the $.post() method to call insert.php file.. this is the ajax request
$.post('action/b_payment.php', {
date: date,
sMan: sMan,
cName: cName,
input_type: input_type,
tamt: tamt,
tpaid :tpaid
},
function(data){
$("#message").html(data);
$("#submit").attr('disabled','disabled');
$("#message").hide();
$("#message").fadeIn(1500); //Fade in the data given by the insert.php file
$( '#formId' ).each(function(){ //This code is for reload the page
window.location.reload(true);
});
});
return false;
});
});
})(jQuery);
如何在 5 秒后显示消息?