![](/img/trans.png)
[英]Can we use partial code from one html file to another html/php file?
[英]Can I use JS to load data from another file inside PHP/HTML code?
我有一個PHP文件,該文件正在從數據庫返回數據。 使用HTML將數據顯示為表格。
現在,我還有另一個“ .php”文件,該文件存儲來自API的數據。 我試圖將這些數據集成到使用PHP顯示的數據中。
PHP / HTML代碼
echo "
<div id='filter-result'>
<table width='100%'>
<tbody>
<tr>
<td rowspan='2'><img src={$row['image']} /></td>
<td><h3>{$row['Name']}</h3></td>
<td rowspan='1' style='font-size:20px'><div id='container-table'></div></td>
<td rowspan='2'><a href={$row['link']} style='text-decoration:none;'>Buy Now</a></td>
</tr>
<tr>
<td rowspan='1'>R</td>
<td>Volume <br>
{$row['volume']}</td>
</tr>
</tbody>
</table>
</div>";
JS代碼
<script>
$('document').ready(function(){
refreshData();
})
function refreshData() {
$('#container-table').load("data.php", function(){
setTimeout(refreshData, 10000);
});
}
</script>
您的代碼也可以正常工作,請檢查路徑。 將一頁加載到另一頁的正常方法是以下方法
$(".testtest").load('stack1.php');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.