2013-04-28 57 views
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秒后的消息?

+0

使用的setTimeout(函数(){window.location.reload(真);},5000); – 2013-04-28 08:08:51

+0

其工作,谢谢... – 2013-04-28 09:48:56

回答

0

尝试

setTimeout(function() { window.location.reload(true); }, 5000); 
+0

哇,gr8,谢谢泰米尔语,它的工作完美! – 2013-04-28 09:48:01

0

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

// This code will execute after 5 seconds 
setTimeout(function() { 
    alert('Hello world'); 
}, 5000); 
+0

非常感谢Eloims的回复 – 2013-04-28 09:48:25

1

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

setInterval(function(){ //display message 
},3000); 
-1
setTimeout(function() { 
    window.location.reload(true); 
}, 5000);