ajax中獲取xmlHttp對象方法
?xmlhttp對象的獲取與ie瀏覽器的版本有很大的關系,我們不能ActiveXObject("Microsoft.XMLHTTP")一個對象,這樣在大多數情況下是沒有問題的,但是在有些ie中,這樣new是不行的,所有我們獲取xmlhttp對象是不能這樣的。

function?XMLHTTP()?
{
????var?xmlHTTP;
????var?msxmlhttp?=?new?Array(
????'Msxml2.XMLHTTP.5.0',
????'Msxml2.XMLHTTP.4.0',
????'Msxml2.XMLHTTP.3.0',
????'Msxml2.XMLHTTP',
????'Microsoft.XMLHTTP');

????for?(var?i?=?0;?i?<?msxmlhttp.length;?i++)?
{

????????try?
{
????????????xmlHTTP?=?new?ActiveXObject(msxmlhttp[i]);

????????}?catch?(e)?
{
????????????xmlHTTP?=?null;
????????}
????}

????if(!xmlHTTP?&&?typeof?XMLHttpRequest?!=?"undefined")
????xmlHTTP?=?new?XMLHttpRequest();
????return?xmlHTTP;
}




























posted on 2007-04-01 14:34 冷面閻羅 閱讀(1637) 評論(2) 編輯 收藏 所屬分類: ajax