Home > Backend Development > PHP Tutorial > javascript - 不刷新页面就可以更新数据是怎么弄的?

javascript - 不刷新页面就可以更新数据是怎么弄的?

WBOY
Release: 2016-06-06 20:15:21
Original
1644 people have browsed it

例如一个订单提醒,我不刷新页面订单的数量会自动变化

回复内容:

例如一个订单提醒,我不刷新页面订单的数量会自动变化

1 ajax http轮询
2 long-polling
3 websocket长连接
4 基于flash socket实现

以上是4种方法。 还有其他。
推荐2和3. 简单场景,并发不大也可以用1. 1实现最简单。

Ajax异步请求

setInterval + Ajax

1.js 做一个定时器
2.5分钟请求一次ajax
3.回调的值进行数量赋值

AJAX/WEBSOCKET

fetch轮询

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template