guolang2116 发表于 2013-1-29 10:45:34

ajax 支持 frifox IE

 //核心对象变量
    var xmlHttp;
    //区分浏览器创建XMLHttpRequest核心对象
    function create(){
     if (window.XMLHttpRequest) // Mozilla, Safari, ...
  {
      xmlHttp = new XMLHttpRequest();////如果浏览器直接支持window.XMLHttpRequest对象
  }
  else if (window.ActiveXObject) // IE,//如果浏览器支持window.ActiveXObject对象
  {
    try {
     xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
     }
    catch (e)
     {
      try
      {
       xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e)
      {}
     }
  }
    }
 
 
    //ajax核心执行方法(此处为提交到servlet处理后,返回纯文本)
    function linklogBlackList(type,perID){
        if(!confirm('你确认要进行此操作??')) {
               return;
           }else{
            create();
          document.thisForm.beOperPerID.value = perID;
          document.thisForm.type.value = type;
       var URL = "linklogBlackList.jsp?type=" + type + "&perID=" + perID;
       xmlHttp.open("GET",URL,true);
       xmlHttp.onreadystatechange=callback;
       xmlHttp.send(null);
           }
    }
 
 
    //回调函数
    function callback(){
     if(xmlHttp.readyState == 4){
      if(xmlHttp.status == 200){
       var v = xmlHttp.responseText;
       if(/^\s*ok\s*$/.test(v)){
           var perid = document.thisForm.beOperPerID.value;
           if(document.thisForm.type.value =="add"){
                     document.getElementById(perid).onclick=function(event){
                         linklogBlackList('remove', perid);
                     };
          document.getElementById(document.thisForm.beOperPerID.value).innerHTML = '移出';
           }else{
                     document.getElementById(document.thisForm.beOperPerID.value).onclick=function(event){
                         linklogBlackList('add', perid);
                     };
            document.getElementById(document.thisForm.beOperPerID.value).innerHTML = '加入';
              }
           alert('操作成功!');
       }else{
         alert('操作失败!请重试');
          }
      }
     }
    }
页: [1]
查看完整版本: ajax 支持 frifox IE