我试图用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]);
}
});
}
解决方法:
试试这个…
$('#lastTs').text(data[0].UPDATE_TIME);