javascript - AJAX get() data -
i have block of jquery uses $.get()
method in setinterval()
. don't understand how data second url jquery code.
jquery:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> <script type="text/javascript"> setinterval(function() { $.getjson("check_time.php", function(update) { if (update) { $("#slideshow").load("phppage.php"); } }); }, 600000); </script>
php - check_time.php
<?php require_once('connect_pdo.php'); header('content-type: application/json'); $stmt = $conn->prepare("$sqlst = $conn->prepare("select count(*) count ads lastupdate > now() - interval 10 minute"); $sqlst->execute(); $row = $sqlst->fetch();"); $stmt ->execute(); $row = $stmt ->fetch(); $update = $row['count'] > 0; $updtstatus = json_encode($update); echo "$updtstatus"; ?>
i not getting variable check_time.php
update
variable in function(update)
.
small alter in php page
$updtstatus = json_encode(array('count'=>$update)); echo $updtstatus;
now json in fact {"count":"true"}
. change if
statement slightly.
$.getjson("check_time.php", function(update) { if (update.count===true) { $("#slideshow").load("phppage.php"); } else { console.log("no results"); } });
this fiddle simulates above answer
Comments
Post a Comment