Sometimes, you need the server to actively push data to the browser, here with Ajax to achieve this function, specifically, see here:
<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 user is logged in, return if (UID) {retur
n;
}//Open modal box, load data from remote by remotely 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 = Setinter
Val (Ajax_request, 3000);
});
});
Ajax request functions, function ajax_request () {i++; If you have requested 20 this does not request success, then force the end, give the hint information, because every 3s call once, for 20 times, is about a minute of the time if (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: {"Scen E_ID ": $ (' #scene_id '). Val ()}, Success:function (msg) {if (1 = msg.status) {$ ('. Login_inf O1 '). html (' <span style= ' color: #0C9; "
> ' +msg.info+ ' </span> ');
SetTimeout (refresh, 3000);
return;
}}, Error:function () {}});
}//Overloaded page function refresh () {location.reload (); } </script>
The above is the entire content of this article, I hope to help you learn.