zoukankan      html  css  js  c++  java
  • XMLHttpRequest


    1)说明
      XmlHttp提供了网页加载后与服务器进行通信的方法。XmlHttp最大的用处是可以更新网页的部分内容而不需要刷新整个页面。

    2)创建
       IE:    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");     
       非IE:  httpRequest = new XMLHttpRequest();

    3)get请求例子

    var xmlhttp;

        function loadXMLDoc(url) {

            xmlhttp = null;

    if (window.XMLHttpRequest) {// code for all new browsers

                xmlhttp = new XMLHttpRequest();

            }

    else if(window.ActiveXObject)

            {// code for IE5 and IE6

                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

            }

            if (xmlhttp != null) {

      xmlhttp.onreadystatechange = state_Change;

      xmlhttp.open("GET", url, true);

                xmlhttp.send(null);

            } else {

                alert("Your browser does not support XMLHTTP.");

            }

            console.log("the xml has been loaded");

        }

        function state_Change() {

    if (xmlhttp.readyState == 4) {// 4 = "loaded"

                if (xmlhttp.status == 200) {// 200 = OK

       var data = xmlhttp.responseXML.getElementsByTagName_r("welcome-file")[0].firstChild.data;

                    processData(data);

                // ...our code here...

                } else {

                    alert("Problem retrieving XML data");

                }

            }

        }

        function processData(data){

            console.log("Data is : ",data);

            var text= document_createTextNode(data);

            var p = document.getElementByIdx_x("p1");

            p.a(text);

        }

  • 相关阅读:
    Remove menucool tooltip trial version
    笔记:Linux(AWS Redhat)开机启动workman进程(/etc/rc.local必须是755权限)
    workman项目设置开机自启动
    Linux应用之crontab定时任务的设置
    在aws ec2上使用root用户登录
    date_default_timezone_set()问题解决方案(PHP5.3以上的)
    Potatso Lite:[限免]ios 自由上网利器
    5+ App开发入门指南
    Nginx或Apache通过反向代理配置wss服务
    phpstudy安装redis
  • 原文地址:https://www.cnblogs.com/wishyouhappy/p/3650969.html
Copyright © 2011-2022 走看看