Here to achieve the function is: by scanning Code micro-letter public number with parameters of two-dimensional code, to log on to the site.
But obviously, if Ajax uninterrupted request server, this will aggravate the load of the server, so this example uses JS setinterval to periodically invoke the implementation of an AJAX function to request data to the server, Use the Clearinterval function to empty the timer when the request succeeds or if a certain number of times is not successful.
Code and comments are as follows: (The backend adopts thinkphp implementation, so the JS code contains some thinkphp syntax rules)
<script type= "Text/javascript" src= "__css__/bootstrap-3.3.5-dist/js/bootstrap.min.js" ></script> <
Script type= "Text/javascript" > var uid = "{$uid}";
var i = 0;
var timer; $ (). Ready (function () {//Open Sweep code login modal box $ (' #login '). Click (function () {//If the user is already logged in, return the IF (UID) {returns;}//Open modal box.
Remotely load data from remote option (' #loginModel '). Modal ({remote: "{: U (' User/login ')}"});
});
Empty the data after the modal box is hidden $ ("#loginModel"). On (' Hidden.bs.modal ', function () {$ (this). Removedata ("Bs.modal");}); When the modal box is displayed, the timer is requested to server $ (' #loginModel ') once every three seconds, by returning it periodically to request the data. On (' Shown.bs.modal ', function (e) {timer = SetInterval (
Ajax_request, 3000);
});
}); Ajax request Function Ajax_request () {i++////////////////////////////////////////////////////////////// '. Login_info1 '). html (' <span style= ' color:red;
> Login timeout, please refresh the page if required ~</span> ');
Clearinterval (timer);
return; } $.ajax ({type: "post", url: "{: U (' User/login_qrcode ')}", timeout:3000, data: {"scene_id": $ (' #scene_id '). Val ()}, suc Cess:function (msg{if (1 = msg.status) {$ ('. Login_info1 '). html (' <span style= ' color: #0C9; "
> ' +msg.info+ ' </span> ');
SetTimeout (refresh, 3000);
return;
}}, Error:function () {}}); }//Overloaded page function refresh () {location.reload ();} </script>
OK, the code is over, I hope to help you!