Ajax about Redirection

Source: Internet
Author: User

Ajax is asynchronous JavaScript and XML, asynchronous JavaScript and XML, where the primary user interacts with the server data without refreshing the page.

The main object used by Ajax is XMLHttpRequest (ActiveXObject in IE5, IE6)

if (window. XMLHttpRequest) {

XMLHTTP = new XMLHttpRequest ();

}

else{

Xmlttp = new ActiveXObject ("Microsoft.XMLHTTP");

}

Xmlhttp.open (Method,url,async);

Xmlhttp.setrequestheader ()

Xmlhttp.onreadystatechange = function () {

if (Xmlhttp.readystate ==4&&xmlhttp.status==200) {

Xmlhttp.getresponseheader (String)

Xmlhttp.responsexml

Xmlhttp.responsetext

}

}

Xmlhttp.send (string);

---------------------------------------------------------------------------------------------------------

&.ajax ({

Type: "GET",

URL: "/http",

Success:function (msg) {},

Error:function (Xmlhttprequest,textstatus,errorthrow) {},

statuscode:{

404:function () {}

},

Complete:function (xmlhttprequest,textstatus) {}

});

Normally, Ajax sends data to the specified URL in a specified way, and when the server finishes processing it returns status 200, and Content-type:text/plain data, the client receives the returned data for processing. If the session expires when the AJAX data is sent, the server requires redirection to the landing page, and the foreground does not get a status code of 302, and the XMLHttpRequest object initiates a redirect request directly to the background and then returns the status 200,content-type: Text/html;msg and ResponseText are the HTML for landing pages.

In complete, the page is displayed if the returned Content-type is text/html

document.write (Xmlhttprequest.responsetext);

Document.close ();(required)

If the AJAX request is sent in a nested page, the landing page is displayed in the topmost page and can be called in the login page

if (top.location! = window.location) {
Top.location = window.location;
}

Prevents page nesting.

Ajax about Redirection

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.