• 自己写的封装好的简单的AJAXjavascript


      
    //Ajax Function
     
    var reqObj; //Creat Null Instence
     
    //Run Ajax (string urladdress,bool IsAsy,string method,string parameters)
    function DoRequest(url,isAsy,method,parStr) 
    {
     
        reqObj = false;
     
        if (window.XMLHttpRequest) //compatible Mozilla, Safari,...
        {
           
            reqObj = new XMLHttpRequest();              //Creat XMLHttpRequest Instance
           
            if (reqObj.overrideMimeType)                //if Mime Type is false ,then set MimeType 'text/xml'
            {
                reqObj.overrideMimeType('text/xml');
            }
       
        }
       
        else if (window.ActiveXObject) //compatible IE
        {
       
            try
            {
                reqObj = new ActiveXObject("Msxml2.XMLHTTP"); //Creat XMLHttpRequest Instance
           }
            catch (e)
            {
                try
                {
                    reqObj = new ActiveXObject("Microsoft.XMLHTTP"); //Creat XMLHttpRequest Instance
                }
                catch (e)
                {}
            }
       
        }
     
        //if reqObj is false,then alert warnning
        if (!reqObj)
        {
           
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
       
        }
       
       
        reqObj.onreadystatechange = GetRequest; //set onreadystatechange Function
       
        reqObj.open(method, url, isAsy);        //set open Function
       
        reqObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); //set RequestHeader
       
        reqObj.send(parStr);   //do send and send parameters
     
    }
     
     
    //get Service Response information Function
    function GetRequest()
    {
     
        //judge readystate information
        if (reqObj.readyState == 4)
        {
            //judge status information
            if (reqObj.status == 200)
            {
                Ajax(reqObj);   //do custom Function at Ajax() and trans parameter reqObj
            }
            else
            {
                alert('There was a problem with the request.'+reqObj.status); //else alert warnning
            }
      
        }
     
    }
       
       
  • 相关阅读:
    通过网络方式安装linux的五种方法
    谈FTP服务器攻击技术及其展望 (下)
    谈FTP服务器攻击技术及其展望 (修改中)
    Fedora 14 x64 试用手记
    加固Samba安全三法
    VMWare高可用集群在企业的应用
    Leetcode-1008 Construct Binary Search Tree from Preorder Traversal(先序遍历构造二叉树)
    Leetcode-1006 Clumsy Factorial(笨阶乘)
    Leetcode-1007 Minimum Domino Rotations For Equal Row(行相等的最少多米诺旋转)
    Leetcode-1005 Maximize Sum Of Array After K Negations(K 次取反后最大化的数组和)
  • 原文地址:https://www.cnblogs.com/ZetaChow/p/2237381.html
Copyright © 2020-2023  润新知