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("评论发表失败,评论内容含有非法信息!"); 
      }
     }
  • 相关阅读:
    docker怎么修改之前run时的env
    yum安装mysql
    springboot服务的Dockerfile
    openssh升级到8.4
    rpm与yum执行无反应
    ubuntn离线安装docker-ce
    centos7部署docker
    解决5版本的elasticsearch-head连接6版本的elasticsearch查询不到数据问题
    docker搭建elasticsearch:7.6.2并开启x-pack
    原生js 实现图片的拖拽缩放
  • 原文地址:https://www.cnblogs.com/lcuzhanglei/p/2624331.html
Copyright © 2011-2022 走看看