php+ajax+jquery 定时刷新页面数据

testajax.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gbk" />

<title>testajax</title>

</head>

 

<body>

<script src='http://www.kuitao8.com/images/js/jquery-1.9.1.min.js'></script>

    <script type= "text/javascript">

$(document).ready(function() {

 

    function update() {

      $.ajax({

       type: 'GET',

       url: 'ajax.php',

       success: function(data) {

          $("#timer").html(data);

          //window.setTimeout(update, 1000);

       },

      });

     }

    setInterval(function(){update();}, 1000);

     //update();

 

});

</script>

<div style="margin:80px auto;width:500px;font-size:32px;color:red;">

<div id="timer"> </div>

</div>

</body>

</html>

 

ajax.php

<?php

    header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . 'GMT');

    header('Cache-Control: no-cache, must-revalidate');

   

    include_once 'inc/conn.php';

    include_once 'inc/utility2.php';

    include_once 'inc/utility_all.php';

    include_once 'inc/utility.php';

   

    global $connection;

   

    $stunum="4257330415748211";

    $snum='3';

    $sql = "select * from jo_reviewmsg where pnum='{$stunum}'  and snum='{$snum}' and status='2' order by id desc limit 1";

    $result=mysql_query($sql,$connection);

    if($row=mysql_fetch_array($result)){

        $flag=$row['flag'];

        $reason=$row['reason'];

        $retstr=$flag.$reason;

    }

    else

        $retstr='';

 

    date_default_timezone_set("Asia/Shanghai");

    echo date("Y-m-d H:i:s")." ret=".$retstr;

?>

posted on 2016-11-07 17:01  xihong  阅读(835)  评论(0编辑  收藏  举报

导航