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

        }

  • 相关阅读:
    JavaScript Eval 函数使用
    WPFToolkit Calendar & DatePicker 使用介绍
    Windows Mobile 6.5 配置环境,数据库访问,部署简单实例
    ThreadPool.QueueUserWorkItem 方法 (WaitCallback)
    Windws Mobile 6.5 Professional ADO.NET数据访问
    WPF调用Web Services
    c#中Interface的理解
    PagesSection.MaintainScrollPositionOnPostBack 属性
    EclipseRCP中文语言包版本不一致,导致导出错误
    SWT美化开源控件网站
  • 原文地址:https://www.cnblogs.com/wishyouhappy/p/3650969.html
Copyright © 2011-2022 走看看