Sagar Gopale Sagar Gopale - 7 days ago 5
jQuery Question

showing php jsonencode array result into ajax success function

I am trying to show result of my php code to ajax file with jquery but i dont know how to do it.final array [{"UPDATE_TIME":"2016-11-28 06:51:51"}] i want to show this result through 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]);

}
});
}

Answer

Try this...

$('#lastTs').text(data[0].UPDATE_TIME);
Comments