2011-05-26 22 views
1

我有此腳本我怎麼解決這阿賈克斯PHP腳本

index.html

<html> 
    <head> 
     <title>Ajax with jQuery Example</title> 
     <script type="text/JavaScript" src="jquery.js"></script> 
    <script type="text/javascript"> 
     $(document).ready(function(){ 
     setInterval(function(){ 
     $("#quote p").load("script.php"); 
     }, 10000); 
    });</script> 
    <style type="text/css"> 
     #wrapper { 
      width: 240px; 
      height: 80px; 
      margin: auto; 
      padding: 10px; 
      margin-top: 10px; 
      border: 1px solid black; 
      text-align: center; 
     } 
     </style> 
    </head> 
    <body> 
     <div id="wrapper"> 
     <div id="quote"><p> </p></div> 

     </div> 
    </body> 
    </html> 

的script.php

<?php 

echo "Hello how are you";?> 
加載index.html的它,當

是空白的10秒,那麼它開始運作..如何擺脫空白,以及如何在瀏覽器加載時立即顯示?

+0

你確實意識到你正在設置10秒的時間間隔,因此爲什麼你在10秒內什麼也看不到? – martynthewolf 2011-05-26 08:58:16

回答

4

setInterval()調用工作作爲設計:它說「在10秒鐘,然後每隔秒,這樣做......」

添加一個單獨的「負荷」呼做初步灌裝:

$(document).ready(function(){ 
    $("#quote p").load("script.php"); // <--- Add this 

    setInterval(function(){ 
    .... 
+0

非常感謝的人.... – 2011-05-26 09:05:07

+0

但在ie 8這個代碼是不做異步數據流.. – 2011-05-26 11:35:14