2012-06-06 46 views
0

我沒有得到任何javascript錯誤,代碼得到正確渲染,但仍然服務器不顯示頁面上的數據。 請檢查下面的代碼。Javascript stockticker:沒有顯示數據在PHP頁面

<style type="text/css"> 
#marqueeborder { 
    color: #cccccc; 
    background-color: #EEF3E2; 
    font-family:"Lucida Console", Monaco, monospace; 
    position:relative; 
    height:20px; 
    overflow:hidden; 
    font-size: 0.7em; 
} 
#marqueecontent { 
    position:absolute; 
    left:0px; 
    line-height:20px; 
    white-space:nowrap; 
} 
.stockbox { 
    margin:0 10px; 
} 
.stockbox a { 
    color: #cccccc; 
    text-decoration : underline; 
} 
</style> 

</head> 

<body> 
    <div id="marqueeborder" onmouseover="pxptick=0" onmouseout="pxptick=scrollspeed"> 
<div id="marqueecontent"> 


<?php 

    // Original script by Walter Heitman Jr, first published on http://techblog.shanock.com 

    // List your stocks here, separated by commas, no spaces, in the order you want them displayed: 
    $stocks = "idt,iye,mill,pwer,spy,f,msft,x,sbux,sne,ge,dow,t"; 

    // Function to copy a stock quote CSV from Yahoo to the local cache. CSV contains symbol, price, and change 
    function upsfile($stock) { copy("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=sl1c1&e=.csv","stockcache/".$stock.".csv"); } 

    foreach (explode(",", $stocks) as $stock) { 

     // Where the stock quote info file should be... 
     $local_file = "stockcache/".$stock.".csv"; 

     // ...if it exists. If not, download it. 
     if (!file_exists($local_file)) { upsfile($stock); } 
     // Else,If it's out-of-date by 15 mins (900 seconds) or more, update it. 
     elseif (filemtime($local_file) <= (time() - 900)) { upsfile($stock); } 

     // Open the file, load our values into an array... 
     $local_file = fopen ("stockcache/".$stock.".csv","r"); 
     $stock_info = fgetcsv ($local_file, 1000, ","); 

     // ...format, and output them. I made the symbols into links to Yahoo's stock pages. 
     echo "<span class=\"stockbox\"><a href=\"http://finance.yahoo.com/q?s=".$stock_info[0]."\">".$stock_info[0]."</a> ".sprintf("%.2f",$stock_info[1])." <span style=\""; 
     // Green prices for up, red for down 
     if ($stock_info[2]>=0) { echo "color: #009900;\">&uarr;"; } 
     elseif ($stock_info[2]<0) { echo "color: #ff0000;\">&darr;"; } 
     echo sprintf("%.2f",abs($stock_info[2]))."</span></span>\n"; 
     // Done! 
     fclose($local_file); 
    } 
?> 
<span class="stockbox" style="font-size:0.6em">Quotes from <a href="http://finance.yahoo.com/">Yahoo Finance</a></span> 

</div> 
</div> 
</body> 
<script type="text/javascript"> 

    // Original script by Walter Heitman Jr, first published on http://techblog.shanock.com 

    // Set an initial scroll speed. This equates to the number of pixels shifted per tick 
    var scrollspeed=2; 
    var pxptick=scrollspeed; 
var marqueediv=''; 
var contentwidth=""; 
var marqueewidth = ""; 
    function startmarquee(){ 
     alert("hi"); 
     // Make a shortcut referencing our div with the content we want to scroll 
     marqueediv=document.getElementById("marqueecontent"); 
     //alert("marqueediv"+marqueediv); 
     alert("hi"+marqueediv.innerHTML); 

     // Get the total width of our available scroll area 
     marqueewidth=document.getElementById("marqueeborder").offsetWidth; 
     alert("marqueewidth"+marqueewidth); 
     // Get the width of the content we want to scroll 
     contentwidth=marqueediv.offsetWidth; 
     alert("contentwidth"+contentwidth); 
     // Start the ticker at 50 milliseconds per tick, adjust this to suit your preferences 
     // Be warned, setting this lower has heavy impact on client-side CPU usage. Be gentle. 
     var lefttime=setInterval("scrollmarquee()",50); 
     alert("lefttime"+lefttime); 
    } 

    function scrollmarquee(){ 
     // Check position of the div, then shift it left by the set amount of pixels. 

     if (parseInt(marqueediv.style.left)>(contentwidth*(-1))) 
      marqueediv.style.left=parseInt(marqueediv.style.left)-pxptick+"px"; 
     //alert("hikkk"+marqueediv.innerHTML);} 
     // If it's at the end, move it back to the right. 
     else{ 
      alert("marqueewidth"+marqueewidth); 
      marqueediv.style.left=parseInt(marqueewidth)+"px"; 
     } 
    } 

    window.onload=startmarquee; 

</script> 
</html> 

以下是服務器顯示頁面。

Stockticker

Updated StockTicker Image

我已經更新了截圖你的建議,我提出在HTML變化太大,檢查什麼是孩子開發出

回答

3

1)首先移動 </body>在你的javascript之後。
2)你的父母 div(ID marqueeborder)具有20像素和溢出隱藏的高度,所以cild div(ID marqueecontent)將板缺,改變你的HTML:

<div id="marqueeborder" onmouseover="pxptick=0" onmouseout="pxptick=scrollspeed"></div> 
<div id="marqueecontent"> 
... 
</div> 

和替換#的CSS marqueecontent position:absolute; left:0px;position: relative;

我希望這有助於...

=== UPDATE ===

正如my example你只需要JavaScript的移動到<head>。 html不需要改變!

+0

我已更新我的答案並添加了一個示例。 – scessor

+0

感謝您的建議,我警告html檢查,什麼是在孩子開發中,我被它所懇求,我已經添加了SC,你能否提供我的解決方案嗎? – developer

+0

好吧,主要問題是PHP錯誤。 yahoo csv不能被複制。其他人是這個錯誤的結果。存在路徑'stockcache'? – scessor

0

看着原來的網站,上面寫着:

「如果是與stockcache目錄中的問題,該腳本將 可能打印‘對每一隻股票入門0.00↑0.00’相反,它看起來 如果你的HTTP服務器正在吐出PHP代碼,而不是正確解析它 ,這可能與服務器配置錯誤有關,或者與頁面其他地方的衝突代碼有關,不幸的是,我不能再更多地瞭解 上下文,例如所討論網頁的源代碼 ,服務器OS,H TTPD和PHP 版本及其配置。「

在託管幫助中擡頭髮現它必須允許php(如果它在html中),必須創建一個.htaccess文件並添加託管公司給我的行,與他們的支持聊天問題已解決**