js 实现简单的轮询
生活随笔
收集整理的這篇文章主要介紹了
js 实现简单的轮询
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在實際開發中,經常會有輪詢的效果。
1、js實現輪詢效果==》使用setTimeout,clearTimeout方法
function setTimer () {let timeraxios.post(url, params).then(function (res) {if(res){console.log(res);timer = setTimeout(() => {this.setTimer()}, 5000) }else {clearTimeout(timer) //清理定時任務}}).catch(function (error) {console.log(error);}); },?2.HTML5推出新的對象:websocket
?
轉載于:https://www.cnblogs.com/phermis/p/11394508.html
總結
以上是生活随笔為你收集整理的js 实现简单的轮询的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: js 实现文件导出、文件下载
- 下一篇: 算法题解:动态规划解0-1背包问题