【发布时间】:2017-06-26 11:56:39
【问题描述】:
PHP 代码
<?php
$url = "https://www.bitstamp.net/api/ticker/";
$fgc = file_get_contents($url);
$json = json_decode($fgc, true);
$price = $json["last"];
$high = $json["high"];
$low = $json["low"];
$date = date("m-d-Y - h:i:sa");
$open = $json["open"];
if($open < $price)
{
// price went up
$indicator = "+";
$change = $price - $open;
$percent = $change / $open;
$percent = $percent * 100;
$percentChange = $indicator.number_format($percent, 2);
$color = "green";
}
if($open > $price)
{
// price went up
$indicator = "-";
$change = $open - $price;
$percent = $change / $open;
$percent = $percent * 100;
$percentChange = $indicator.number_format($percent, 2);
$color = "red";
}
$table = <<<EOT
<table>
<tr>
<td rowspan="3" width="60%" id="lastPrice">$$price</td>
<td align="right" style="color: $color;">$percentChange%</td>
</tr>
<tr>
<td align="right">$$high </td>
<td align="right">$$low </td>
</tr>
<tr>
<td colspan="2" align="right" id="timeDate">$date</td>
</tr>
</table>
EOT;
echo $table;
?>
HTML 和 JS
<html>
<head>
<title> Bitcoin Widget </title>
<link rel="stylesheet" type="text/css"href="css/style.css">
<script src="https://code.jquery.com/jquery-3.2.1.js" integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=" crossorigin="anonymous"></script>
</head>
<body>
<div id="container">
</div>
<script>
$('document').ready(function(){
refreshData();
})
function refreshData() {
$('#container').load("data.php", function(){
setTimeout(refreshData, 10000);
});
}
</script>
</body>
</html>
现在我想将此价格代码包含在另一个网页中。所以,我复制了JS并粘贴到相应的HTML文件中,也复制了根目录下的PHP文件,但没有任何显示。
如何将这个小部件包含在另一个 HTML 文件中。
【问题讨论】:
-
在 load() 中创建用于显示价格详细信息的 html,您可以在此 HTML 中使用相同的 php 变量
-
你能提供你的结构吗?
-
我应该在结构中提供什么
-
检查答案。我已经在其中添加了结构
标签: javascript php jquery html