• Ajax


    HttpRequest.prototype.createXmlHttpRequest = function ()
    {
        if (window.XMLHttpRequest)
        {
            var oHttp = new XMLHttpRequest();
           
            return oHttp;
        }
        else if (window.ActiveXObject)
        {
       
            var versions =
           
            [
           
            "MSXML2.XmlHttp.6.0",
           
            "MSXML2.XmlHttp.3.0"
           
            ];
           
            for (var i = 0; i < versions.length; i++)
            {
                try
                {
                    var oHttp = new ActiveXObject(versions[i]);
                    return oHttp;
                }
                catch (error)
                {
                    //do nothing here
                }
            }
        }
        alert("Your browser doesn’t support XMLHttp");
    }

    二、发送请求
    // 请求服务器
    function HttpRequest(sUrl, fpCallback)
    {

        this.request = this.createXmlHttpRequest();//创建请求对象
       
        this.request.open("GET", sUrl, true);//请求方式,地址,是否异步请求:
       
        var tempRequest = this.request;
       
        function request_readystatechange()
        {
            if (tempRequest.readyState == 4)
            {
                if (tempRequest.status == 200)
                {
                    fpCallback(tempRequest.responseText);
                }
                else
                {
                    alert("An error occurred trying to contact the server.");
                }
            }
        }
       
        this.request.onreadystatechange = request_readystatechange;

    }

    HttpRequest.prototype.send = function ()
    {
        this.request.send(null);
    }

  • 相关阅读:
    2. redis的数据类型
    1. redis简介
    6. 职责链设计模式
    9. 桥梁设计模式
    一. 序言
    网络中常见的面试题
    JDBC
    Mybatis批量操作数据的方法
    ORM框架的概述
    Mybatis动态sql技术
  • 原文地址:https://www.cnblogs.com/yuan198094/p/1488427.html
Copyright © 2020-2023  润新知