2013-04-09 26 views
-1

我有一個表格什麼的,這樣說:PHP做間隔

<form name="form1" action="" method="post"> 
<input type="text" name="tfcari" /> 
<input type="submit" name="btcari" /> 
</form> 

<?php 
if (isset($_POST['btcari'])) { 

echo $_POST['tfcari']; 

?> 

如何做這樣的:

點擊提交 - 回聲文字 - 等待5秒鐘 - 回聲文本 (自動) - 等待5秒 - 回顯文本(自動) - ...

謝謝大家。

+3

使用JavaScript或JQuery的。 – 2013-04-09 00:53:39

+0

@Toby' jQuery is JavaScript':) – Phil 2013-04-09 01:08:56

+0

@Phil我知道有人會這麼說,但我只是寫了JavaScript的想法,有人試圖在沒有jQuery庫的普通舊javascript中實現此操作,而不是僅僅執行它與jquery是太可怕的沉思。 :) – 2013-04-09 01:11:45

回答

1

在發送到網站之前進行PHP預處理,所以如果你打算使用睡眠方法,它只會延遲頁面frrom的顯示時間。

的-easiest-的辦法,是使用jQuery的Ajax調用,然後使用setTimeout的呼應文本每5秒:

// Assuming jQuery is linked 
$(function() { 
    // Connect to the php file 
    $.ajax({ 
     url: 'php-file-with-tfcari-var.php', 
     type: 'POST', 
     success: function(data) { 
      // data is what the ajax call returns, let's assume it's the $_POST variable from php 
      var tfcari = data.tfcari; 
      // Now you can loop every 5 seconds with a self calling setTimeout method 
      var poll = (setTimeout(function() { 
       window.document.write(tfcari); 
      }, 5000)(); 
     } 
    }); 
}); 
+0

:)嗯。 undrstand知道。偉大的探索,謝謝弗朗西斯科 – user2126044 2013-04-09 01:19:52

+0

對不起noobs,我運行的代碼,它像不成功?怎麼樣? – user2126044 2013-04-09 01:56:07