下午好,每个人。在PHP中运行Javascript的问题
我有一个持续的问题,下面的代码。我知道Javascript/JQuery和JSON工作正常,正如这里展示的 - http://jsfiddle.net/Dvpmy/13/
我也知道,当我尝试回显JavaScript时省略了PHP工作正常。但是,当我将所有内容组合在一起时,我似乎遇到了问题。 Chrome浏览器正在标记“意外标识符”,Firefox认为在一个参数后面有一个缺失的圆括号。我无法找到和补救。
<html>
<head>
<script type="text/javascript" src="/Portfolio/jquery.js"></script>
<?php
mysql_connect(localhost,"user","password");
@mysql_select_db("database") or die("Unable to select database");
$query="SELECT * FROM quote WHERE view='yes'";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$ID=mysql_result($result,$i,"ID");
$EPIC=mysql_result($result,$i,"EPIC");
echo '<script type="text/javascript">';
echo'$.getJSON("http://query.yahooapis.com/v1/public/yql? q=select%20*%20from%20yahoo.finance.historicaldata%20where%20symbol%20%3D%20%22DES%22%20and%20startDate%20%3D%20%222009-09-11%22%20and%20endDate%20%3D%20%222010-03-10%22&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=?", function(data) { console.log(data); var info = data.query.results.quote[0].Close; var date = data.query.results.quote[0].Date; var high = data.query.results.quote[0].High; $("div.quote").html("Test" $ID <br> $EPIC <br> high); });';
echo '</script>';
$i++;
}
?>
</head>
<body><div class='quote'></div></body></html>
我想提前道歉,如果解决方案明显。所有的援助将受到感谢。
非常感谢。
您还最好在'$(document).ready()'内包装'$ .getJSON'调用,因为在您调用这个元素时,元素还不存在。 – 2012-07-08 12:05:33