|
![](/images/resource/spacer.gif) |
|
ต้องการ Reload ข้อมูล Json จาก url โดยไม่ต้องรีเฟรชหน้านั้นโดยใช้ php |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ใช้ ajax request กลับมา ที่ server เพื่ออ่านค่าใหม่อีกครั้ง
Code (JavaScript)
$(document).ready(()=>{
getNewGolePrize();
});
function getNewGoldPrice(){
$.ajax({
url: 'myhost.com/GetPrice.php', datatype:'json',
success: r=>{
$('div[data-id="gold"]').html( r.gold);
$('div[data-id="us"]').html( r.us);
$('div[data-id="pounds"]').html( r.pound);
setTimeout( getNewGoldPrice, 5000);
}
});
}
Code (PHP)
// GetPrice.php
<?php
$url = 'http://www.thaigold.info/RealTimeDataV2/gtdata_.txt';
$data_json = file_get_contents($url);
echo $data_json;
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2020-06-23 18:15:11 |
By :
Chaidhanan |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 02
|