首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Javascript股票行情: php页面不显示数据

Javascript股票行情: php页面不显示数据
EN

Stack Overflow用户
提问于 2012-06-06 14:40:57
回答 1查看 219关注 0票数 0

我没有收到任何javascript错误,代码只能正确呈现,但仍然无法在页面上显示数据。请检查下面的代码。

代码语言:javascript
复制
 <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>

下面是服务器显示的页面。

我已经用你的建议更新了截图,我也在html中做了更改,以检查child dev正在显示什么。

EN

回答 1

Stack Overflow用户

发布于 2013-12-09 01:37:51

查看了原始网站,上面写着:

“如果是股票缓存目录的问题,脚本可能会为每个股票条目打印”0.00PHP0.00“。相反,看起来您的↑服务器没有正确解析,而是吐出了PHP代码。这可能与服务器配置错误或页面上其他地方的代码冲突有关。不幸的是,在不了解更多上下文的情况下,我无法提供更多详细信息,例如相关网页的源代码、服务器操作系统、HTTPD和PHP版本,以及它们的配置。”

在主机帮助中查找,发现它必须允许php (如果它是在html内),必须创建一个.htaccess文件并添加主机公司给我的行,在与他们的支持人员短暂交谈后,问题得到了解决**

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10909296

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档