1

我有一些 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 秒后显示消息?

4

4 回答 4

1

你可以使用 JavaScript 计时器来做到这一点

setInterval(function(){ //display message
},3000);
于 2013-04-28T08:12:08.070 回答
0

尝试

setTimeout(function() { window.location.reload(true); }, 5000); 
于 2013-04-28T08:10:04.577 回答
0

如果要延迟 javascript 代码执行,可以使用 setTimeout 函数。

// This code will execute after 5 seconds
setTimeout(function() {
    alert('Hello world');
}, 5000);
于 2013-04-28T08:10:14.470 回答
-1
setTimeout(function() {
  window.location.reload(true); 
}, 5000); 
于 2014-07-04T07:15:45.790 回答