ajax 轮询(适合web端二维码请求)
2024-09-01 10:26:09
(前几天 一直弄二维码轮询登录 想了半天 总算弄出来了 分享给大家 ^-^)
轮询:
所谓轮询 肯定需要 setInterval 但是怎么加ajax请求 需要有点小问题而且轮询成功后需要停止 下来看代码吧
var tis = setInterval(function(){$.ajax(getting)},3000);//{调用ajax(自己封装的数据)},每3秒执行一次
var getting = {
type:'GET',
url://地址,
success: function (obj) {
console.log(obj)
//这里需要你判断服务器返回的数据
//成功后取消clearTimeout(tis);
},
error: function (err) {
console.log(err);
}
}
大家如果写扫码登录的话 肯定在URL地址拼接时间戳 给大家写一个时间戳的封装函数 直接调用即可
Date.prototype.format = function (format) {
var args = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3), //quarter
"S": this.getMilliseconds()
};
if (/(y+)/.test(format))
format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var i in args) {
var n = args[i];
if (new RegExp("(" + i + ")").test(format))
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? n : ("00" + n).substr(("" + n).length));
}
return format;
};
var tims = new Date().format("yyyyMMddhhmmssS")//调用格式根据需求比如:("yyyy-MM-dd-hh-mm-ssS")
console.log(tims)
^-^
最新文章
- How to Use Lucene.NET with Windows Azure SQL Database
- 【leetcode】Spiral Matrix(middle)
- SQL查询语句去除重复行
- 全栈式JavaScript
- Linux内核--usb子系统的分析
- location.hash &;&; location.href
- [洛谷1580]yyy loves Easter_Egg I
- shell中case的用法学习笔记
- Building Local Unit Tests
- 2014第8周一JS正则小问题
- Struts2学习笔记③
- xlwt 官网的例子
- thinkphp实现like模糊查询实例
- 网络爬虫&;起点中文网完本榜500部小说
- linux下 /usr/bin/ld: 找不到 -ldhnetsdk的解决方法
- Android 数据库框架总结(转)
- 复制文件描述符---dup
- Android 查看自己的keystore的别名及相关信息
- golang模拟新浪微博登录
- SRS Audio Sandbox没有声音怎么办
热门文章
- python pandas进行条件筛选时出现ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().”
- [翻译] ASP.NET Core 3.0 的新增功能
- 离线环境下进行pip包安装
- JAVA设计模式-动态代理(Proxy)源码分析
- Mysql - 关于relay_log_recovery参数的测试
- SpringBootSecurity学习(06)网页版登录方法级别的权限
- 基于Docker搭建大数据集群(一)Docker环境部署
- Spring 梳理-el表达式和jstl
- 节点操作--JavaScript
- windows下查看进程及结束进程命令