Ajax polling (for web-side QR code requests)

Source: Internet
Author: User

(The last few days have been made QR code polling login thought for a long time finally came out to share to everyone ^-^)

Polling:

The so-called polling definitely needs setinterval But how to add AJAX requests needs a little bit of a problem and you need to stop looking at the code after a successful poll

 var  tis = setinterval (function  () {$. Ajax (getting)},3000); // {calls Ajax (own encapsulated data), executes once every 3 seconds  var  getting = {type:  ' GET ' 

If you write a scan code to log in, it must be in the URL address stitching time stamp to everyone to write a timestamp of the package function directly call can

Date.prototype.format =function(format) {varargs = {        "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(varIinchargs) {        varn =Args[i]; if(NewRegExp ("(" + i + ")"). Test (format)) format= Format.replace (regexp.$1, regexp.$1.length = = 1? N: ("xx" + N). substr ("" +( N). length)); }    returnformat;};varTims =NewDate (). Format ("Yyyymmddhhmmsss")//Call format according to requirements such as: ("Yyyy-mm-dd-hh-mm-sss")Console.log (Tims)

^-^

Ajax polling (for web-side QR code requests)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.