栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

jQuery Ajax显示数据

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

jQuery Ajax显示数据

当然,建立一个基本的彗星风格的长轮询非常简单:

PHP:

<?php    $data = null;    while ($data ==  null)    {         $data = find_data($_REQUEST['last_update']); // This is up to you.         // Although you may do a DB query, that sort of breaks the model         // from a scalability perspective.  The point in this kind of         // operation is to rely on external data to know that it needs to          // update users, so although you can keep your data in a DB, you'll         // want a secondary storage mechanism to keep from polling it.         //         // Conceptually, you'd put new information into this data storage         // system when something changes (like new data from an external         // source.  The data storage system could check to see if a file         // has been updated or if there is new data in something like a         // memcached key.  You'd then consume the data or otherwise          // mark it as used.         sleep(5);    }    echo json_enpre($data);

Javascript:

 function setListener() {      $.ajax({url: 'updater.php',       dataType: 'json',       success: function(data, status, xhr) {   // do something, such as write out the data somewhere.   setListener();},       error: function(){    setTimeout(setListener,10000);}       }); }


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/418184.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号