Using jquery Ajax filtering for rest uninterrupted sessions

Source: Internet
Author: User

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 ();});}});


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.