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