• 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);

        }

  • 相关阅读:
    将当前日期转换成年-月- 日格式
    js修改title
    Window.open()方法参数详解总结(转)
    js(jQuery)获取时间的方法及常用时间类
    用express搭建一个简单的博客系统
    字符串、数组相互转换 对象转换为数组的方法
    多文件上传 input 的multiple 属性
    关于iframe的使用 以及自适应页面高度
    浏览器转换为兼容模式
    分类算法之随机森林
  • 原文地址:https://www.cnblogs.com/wishyouhappy/p/3650969.html
Copyright © 2020-2023  润新知