Using jquery Ajax filtering for rest uninterrupted sessions
When a client-server session times out, an AJAX data request is sent and a 403 status code is encountered?
In the shell terminal, when the Super administrator session times out, the password input confirmation is automatically displayed. For the page, is to capture each status code 403 failed request, to log on after the success of a replay, or after the successful landing directly refresh the page?
The development of jquery today should provide the functionality to handle this business. Sure enough to find madpilot rants an article, these problems are solved.
The specific process is:
When the request encounters a 403 error, it is placed in the 403 queue and the login box pops up, and when the login is successful, the unsuccessful request in the queue is automatically re-sent.
However, this scenario is currently flawed: it does not support the use of the Promise style to add success callbacks, success callbacks are written in the options, which means:
Support for Jquery.ajax ("/foo.json", {success:function (data) {//todo}}), and/or Jquery.ajax ("/foo.json") are not supported. Done (function ( Data) {//todo});
The following scenarios refer to the rants scenario and consider the scenario where concurrent requests are 403 failed:
Require (["jquery"],function ($) {//thanks @madpilot rants//see http://myles.eftos.id.au/blog/2011/11/30/ how-to-re-play-an-ajax-request-in-jquery-after-an-authentication-error/#. U-ihifmsx8evar Isdialogshown=false;var Ajaxqueue=[];jquery.ajaxsetup ({statuscode:{//is not logged in or the session fails after login, The server will return the status code 403403:function () {Ajaxqueue.push (this); if (Isdialogshown) {return;} Isdialogshown=true;require (["Infrastructure/user/logindialog"],function (logindialog) {var dialog=new LoginDialog ( "Logindialog", {onfullfilled:function () {Isdialogshown=false;ajaxqueue.foreach (function (context) {$.ajax (context) ;}); Ajaxqueue.length=0;},onrejected:function () {}});d ialog.placeat (document.body, "BeforeEnd") Dialog.open ();});}});