Common AJAX functions create XMLHTTP objects. Differences between IE and Mozilla browsers

Source: Internet
Author: User

Common AJAX functions are used to create XMLHTTP objects, which are different from functions in IE and Mozilla browsers. There are many functions on the Internet that create XMLHTTP objects, which are different from functions in IE and Mozilla browsers. This is quite good and you can use it directly.
Copy codeThe Code is as follows:
Function getRequest (){
Http_request = false;
If (window. XMLHttpRequest ){
// Create XMLHttpRequest for Mozilla, Netscape, Safari, and other browsers
Http_request = new XMLHttpRequest ();
If (http_request.overrideMimeType ){
// If the server response header is not text/xml, you can call other methods to modify the header.
Http_request.overrideMimeType ('text/xml ');
}
} Else if (window. ActiveXObject ){
// Create XMLHttpRequest for Internet Explorer
Try {
Http_request = new ActiveXObject ("Msxml2.XMLHTTP ");
} Catch (e ){
Try {
Http_request = new ActiveXObject ("Microsoft. XMLHTTP ");
} Catch (e ){}
}
}
Return http_request;
}
// Obtain the Url's responseText

Function getResponseText (url)
{
Http_request = getRequest ();
Http_request.open ('get', url, false );
Http_request.send (null );

If (http_request.readyState = 4)
{
// Receives the complete Server Response
If (http_request.status = 200 ){
// The HTTP server response value is OK.
Requestdoc = http_request.responseText;
// Write the string returned by the server to the region where the ID is message on the page.
}
Else {
Requestdoc = http_request.status;
}
}
Return requestdoc;
}
// Obtain the Url's responseXML

Code snippet
Function getResponseText (url)
{
Http_request = getRequest ();
Http_request.open ('get', url, false );
Http_request.send (null );

If (http_request.readyState = 4)
{
// Receives the complete Server Response
If (http_request.status = 200 ){
// The HTTP server response value is OK.
Requestdoc = http_request.responseXML;
// Write the string returned by the server to the region where the ID is message on the page.
}
Else {
Requestdoc = http_request.status;
}
}
Return requestdoc;
}

Related Article

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.