我试图用jquery将我的php代码的结果显示给ajax文件,但我不知道该怎么做。最终数组[{"UPDATE_TIME":"2016-11-28 06:51:51"}]
我想通过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]);
}
});
}
答案 0 :(得分:1)
试试这个......
$('#lastTs').text(data[0].UPDATE_TIME);