以下就是創建XMLHttpRequest完整版的代碼,希望對大家有用~
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
try {
xmlHttpRequest = new ActiveXObject("Msxml3.XMLHTTP");
} catch (e) {
try {
xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}}}
}else if(window.XMLHttpRequest)
{
xmlHttpRequest=new XMLHttpRequest();
if (XMLHttpRequest.overrideMimeType)
xmlHttpRequest.overrideMimeType('text/XML');
}
}