zoukankan      html  css  js  c++  java
  • XMLHttpRequest的使用方法

    这里写个使用XMLHttpRequest调用页面,post数据的js。

    代码
     1 var xhr=false;
     2  if(window.XMLHttpRequest) {
     3   xhr=new XMLHttpRequest();//IE7+,Firefox,Opera,Chorme,Safari
     4             } else {
     5                 try {
     6                     xhr=new ActiveXObject("MSXML2.XMLHTTP");//IE6+
     7                 }catch(e){
     8                     try {
     9                         xhr=new ActiveXObject("Microsoft.XMLHTTP");//IE6也行
    10   }catch(e){return null;}
    11  }
    12 }
    13 
    14 str = "Id=" + document.getElementById("Id").value; 
    15 xhr.open("POST","http://XXX.XXX.XXX",false);
    16 xhr.setRequestHeader("Content-Length",str.length); 
    17 xhr.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
    18 xhr.setRequestHeader("HeaderInfo",document.getElementById("HeaderInfo").value); 
    19 xhr.send(str);
    20 txt1.document.write(xhr.responseText);
    21 
                                   --小小的,有大大的梦想!
  • 相关阅读:
    批量清理harbor镜像
    常用的git命令
    Gentoo网络管理方法总结
    Pelican主题配置:elegant
    Pelican搭建静态博客
    UNIX基础--安装应用程序: Packages 和 Ports
    UNIX基础--Manual Pages
    UNIX基础--Shells
    UNIX基础--进程和守护进程
    UNIX基础--磁盘组织
  • 原文地址:https://www.cnblogs.com/ztlyz/p/1741101.html
Copyright © 2011-2022 走看看