zoukankan      html  css  js  c++  java
  • 自己写的封装好的简单的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
            }
      
        }
     
    }
       
       
  • 相关阅读:
    【python】PyQt5 QAction 添加点击事件
    【环境搭建】安装pyQt5 在pycharm报This application failed to start because no Qt platform plugin could be initialized的问题
    【嵌入式】arduino IDE串口监视器可以正常使用但其他软件发送串口指令没有反应的问题
    【操作系统】bat文件 系统找不到文件路径
    十天冲刺:第二天
    十天冲刺:第一天
    项目需求分析NABCD电梯演讲
    项目需求分析与建议-NABCD模型
    团队开发之团队介绍
    会议1.7
  • 原文地址:https://www.cnblogs.com/ZetaChow/p/2237381.html
Copyright © 2011-2022 走看看