4

I am trying to show result of my php code to ajax file with jquery but I don't 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]);

}
});
}

1 Answer 1

1

Try this...

$('#lastTs').text(data[0].UPDATE_TIME);
Sign up to request clarification or add additional context in comments.

6 Comments

error showing for $(document).ready(function(){ setTs(); }) its saying $ is not defined but nothing showing for main ajax,its showing blank screen,no output
Have you call jquery.min.js ?
no ,its imp to call jquery.min.js? i have added noe google cdn <script src="ajax.googleapis.com/ajax/libs/jquery/3.1.1/…> above script tag $ defined error now gone bt output not coming
Yes it is...without js you can not use jquery..See below link... w3schools.com/jquery/tryit.asp?filename=tryjquery_hide
yes i did same not no error in code but output still not coming
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.