1. 程式人生 > >jquery 拒絕訪問 無法載入 跨域問題

jquery 拒絕訪問 無法載入 跨域問題

var xhr=false;
if(window.ActiveXObject){
    try{xhr = new ActiveXObject("Msxml2.XMLHTTP.4.0");}
    catch(e1){
      try{xhr = new ActiveXObject("Msxml2.XMLHTTP");}
      catch(e2){{xhr = new ActiveXObject("Msxml2.XMLHTTP");}}
    }
}
else if(window.XMLHttpRequest){
/*XMLHttpRequest放最後來建立,這樣在IE7,IE8中雙擊執行或者拖拽進入瀏覽器中瀏覽就
不會出現access is denied 拒絕訪問錯誤了,因為使用的是ActiveXObject來建立ajax物件*/

   xhr= new XMLHttpRequest();
}