zoukankan      html  css  js  c++  java
  • 手写原生态ajax封装代码

    function createAjaxObj(){
     var httprequest=false
     if (window.XMLHttpRequest){ // if Mozilla, Safari etc
      httprequest=new XMLHttpRequest()
      if (httprequest.overrideMimeType)
       httprequest.overrideMimeType('text/xml');
     }
     else if (window.ActiveXObject){ // if IE
      try 
      {
       httprequest=new ActiveXObject("Msxml2.XMLHTTP");
      } 
      catch (e)
      {
       try
       {
        httprequest=new ActiveXObject("Microsoft.XMLHTTP");
       }
       catch (e){}
      }
     }
     return httprequest;
    }
    
     
     
     
     
     
     
     
     
     
     
     
    postStr+="&lan="+document.getElementById("lanVersion").value;
     
    // alert(postStr);
     //实例化Ajax
     var ajax = createAjaxObj(); 
     //通过Post方式打开连接
     ajax.open("POST", url, true); 
     //定义传输的文件HTTP头信息,这一行不能少
     ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");  
     //发送POST数据
     ajax.send(postStr);
     ajax.onreadystatechange = function() { 
      if (ajax.readyState == 4 && ajax.status == 200) { 
    //        document.getElementById("content").value=""
    //        document.getElementById("bntSendProEmail").disabled=false;
            var content=ajax.responseText;
            alert(content); 
      } 
      else if(ajax.readyState != 1 && ajax.readyState != 2 && ajax.readyState != 3&& ajax.readyState != 0)
      {
    //   document.getElementById("bntSendProEmail").disabled=true;
       alert("评论发表失败,评论内容含有非法信息!"); 
      }
     }
  • 相关阅读:
    SpringBoot08-缓存
    Spring注解-自动装配(三)
    Spring注解-生命周期与属性赋值(二)
    Spring注解-组件注册(一)
    剖析SpringMVC流程与整合(八)
    SpringMVC视图解析与配置(六)
    SpringMVC的其他功能(七)
    简单了解SpringMVC(五)
    Java动态代理
    Spring事务(四)
  • 原文地址:https://www.cnblogs.com/lcuzhanglei/p/2624331.html
Copyright © 2011-2022 走看看