Mapping jsonencode php array result to ajax success function

I am trying to show the result of my php code for an ajax file with jquery, but I do not know how to do this. 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]);

}
});
}
+4
source share
1 answer

Try it...

$('#lastTs').text(data[0].UPDATE_TIME);
+1
source

Source: https://habr.com/ru/post/1662113/


All Articles