duanque19820925 2015-05-30 14:56 采纳率: 0%
浏览 170

从服务器获取刷新数据

How can i get latest or fresh data from server (if in server happened new event (for example there are 2 users x,y and x send messages to y and y get this message without refreshing page ) )? I don't want to use setInterval because it repeats all message again and again. Is there any Technique that can i use for this ? I heard about Ajax that technique need to send request to the server but i want when happen an event in the server and webpage get it without refreshing..

  • 写回答

2条回答 默认 最新

  • drq1257 2015-05-30 15:04
    关注

    The first technique is the long polling, which sends request to the server and waits until the server sends something, for example the new message. You must re-send requests to the server each time you get a new message or your request is time out. This technique uses AJAX. Long polling PHP example - How do I implement basic "Long Polling"?

    The second is web sockets, https://en.wikipedia.org/wiki/WebSocket

    this stackoverflow question deals with the implementation of websocket.

    socket.io has a demo of chat application.

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀