4
我試圖用jQuery顯示我的php代碼的結果給ajax文件,但我不知道該怎麼做。最終陣列[{"UPDATE_TIME":"2016-11-28 06:51:51"}]
顯示php jsonencode數組結果到ajax成功函數
我想通過ajax jquery顯示此結果。
<?php
header('Access-Control-Allow-Origin: *');
include_once "dbconfig.php";
$sql = "SELECT UPDATE_TIME
FROM information_schema.tables
WHERE TABLE_SCHEMA = 'vizteyl7_tarining'
AND TABLE_NAME = 'news'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$output[] = $row;
}
echo json_encode($output);
} else {
echo "0 results";
}
$conn->close();
?>
<label>Enter TimeStamp (last updated date: <span id="lastTs"></span>)</label>
$(document).ready(function(){
setTs();
})
function setTs(){
$.ajax({
type: "GET",
url:"http://example.com/stshow.php",
dataType: "json",
success: function(data) {
$('#lastTs').text(data[0]);
}
});
}
試試這個........ –
感謝它did'nt工作..: ( –
得到任何錯誤?.. –