josn

josn.php


    session_start();
    sleep(5);
    header('Content-Type: application/json; charset=utf-8');
    if ( !isset($_SESSION['chats']) ) $_SESSION['chats'] = array();
    echo(json_encode($_SESSION['chats'], JSON_PRETTY_PRINT));//生成josn
<html>

<body>

<p id="back">Original static text</p>
<script type="text/javascript" src="jquery.min.js">
</script>
<script type="text/javascript">
$(document).ready( function () {
  $.getJSON('json.php', function(data) {//获取josn
      $("#back").html(data.first);
      window.console && console.log(data);
    })
  }
);
</script>
</body>

  • $.ajaxSetup({ cache: false }); 不然有的浏览器里得到的是之前缓存的,不是最新的

你可能感兴趣的:(php,javascript)