JS XMLHTTP object IE browser and non IE browser creation method
Example: Create a XMLHTTP object and request an XML document from the server, which is displayed after the document is returned. The following are examples of IE and non-IE explained
1 IE Browser uses ActiveXObject method to create XMLHTTP objects:
var xmlhttpreq = new ActiveXObject ("msxml2.xmlhttp.3.0");
Xmlhttpreq.open ("Get", "Http://localhost/test.xml", false);
Xmlhttpreq.send ();
alert (Xmlhttpreq.responsetext);
2 non-IE browsers use the XMLHttpRequest method to create XMLHTTP objects:
var xmlhttpreq = new XMLHttpRequest ();
Xmlhttpreq.open ("Get", "Http://localhost/test.xml", false);
Xmlhttpreq.send ();
alert (Xmlhttpreq.responsetext);
2.2 After the XMLHTTP object is created, because it is a set of APIs, it has a number of methods and properties, such as the Open (), send (), and responsetext used above.
The XMLHTTP object's code is handled in a more fixed way. So the next thing to do is to follow the example in order to understand it.
Let's look at a complete example
JS compatible ff ActiveXObject Create XMLHTTP method
*/
function Createxmlhttpobject ()
{
var xobject = null;
Try
{
Xobject = new ActiveXObject ("msxml2.xmlhttp.4.0");
}
catch (E)
{
Try
{
Xobject = new XMLHttpRequest ();
if (Xobject.overridemimetype) {
Xobject.overridemimetype (' Text/xml ');
}
}
catch (E)
{
Try
{
Xobject = new ActiveXObject ("Msxml2.xmlhttp");
}
catch (E)
{
Try
{
Xobject = new ActiveXObject ("Microsoft.XMLHTTP");
}
catch (E)
{
Alert ("error:unable to create XML HTTP object!");
}
}
}
}
return xobject;
}
function Initrequest () {
Request = Createxmlhttpobject ();
}