2014-01-22 26 views
0

嗨,我想使用腳本來顯示加載欄,而我的PHP正在執行。我從這個website瞭解到,但是當我做了完全一樣的事情,我的加載欄仍然無法顯示,爲什麼?加載微調圖像,而php正在執行使用腳本

<html> 
    <head> 

<style type="text/css"> 
    div#content { 
    display: none; 
    } 

div#loading { 
    top: 200 px; 
    margin: auto; 
    position: absolute; 
    z-index: 1000; 
    width: 160px; 
    height: 24px; 
    background: url(img/142.gif) no-repeat; 
    cursor: wait; 
} 
</style> 
    <script type="text/javascript"> 
    function preloader(){ 
     document.getElementById("loading").style.display = "none"; 
     document.getElementById("content").style.display = "block"; 
    }//preloader 
    window.onload = preloader; 
</script> 

<style type="text/css"></style> 
</head> 
<body> 
<div id="loading"></div> 
<div id="content" > 

<?php 

sleep(10); 
echo 'This content has been loaded via an AJAX request'; 

?> 
<br> 
</div> 
</body> 
</html> 
+0

風格= 「顯示:無;」> –

+0

你是什麼意思? @Kannan – user2462090

+0

您的ID **加載**是**顯示:無** –

回答

3

只要運行該代碼在任何瀏覽器

<!DOCTYPE html> 
<?php 
@ini_set('zlib.output_compression', 0); 
@ini_set('implicit_flush', 1); 
@ob_end_clean(); 
set_time_limit(0); 
?> 
<html> 
    <head> 
     <style type="text/css"> 
      div#content { 
       display: none; 
      } 
      img#loading { 
       top: 200 px; 
       margin: auto; 
       position: absolute; 
       z-index: 1000; 
       width: 500px; 
       height: 24px; 
       cursor: wait; 
       height: 500px 
      } 
     </style> 
     <style type="text/css"></style> 
    </head> 
    <body> 
     <?php 
     for ($i = 0; $i < 10; $i++) { 
      echo str_repeat(' ', 1024 * 64); // this is for the buffer achieve the minimum size in order to flush data 
      if ($i == 1) 
       echo '<img id="loading" src="img/142.gif" />'; 
     } 
     ?> 
     <div id="content" style="display: block;"> 
      <?php 
      sleep(5); 
      echo 'This content has been loaded via an AJAX request'; 
      ?> 
      <br> 
     </div> 
     <script type="text/javascript"> 
      function preloader() { 
       document.getElementById("loading").style.display = "none"; 
       document.getElementById("content").style.display = "block"; 
      }//preloader 
      window.onload = preloader; 
     </script> 
    </body> 
</html> 

,如果您有以下配置存取權限爲php.ini設置在php.ini並刪除 @ini_set('zlib.output_compression',0); @ini_set('implicit_flush',1);從begining

output_buffering = Off 
implicit_flush = on 
output_compression = Off 

如果你是好奇輸出緩衝click here

1
<?php 

sleep(1000);//increase sleep time 
echo 'This content has been loaded via an AJAX request'; 

?> 

,並刪除style="display: none;"

+0

我曾嘗試過,仍然無法工作 – user2462090