zoukankan      html  css  js  c++  java
  • 支持自定义回调函数的异步调用

        做一个最简单的POST方式异步调用的请求,支持自定义的回调函数,该回调函数获取异步请求返回的XMLDOM对象,代码如下:

    function postRequest(url,parameters,callBack){
        
    var xmlHttp = getXmlHttp(); //create xmlHttpRequest
        if(xmlHttp !=null){
            xmlHttp.onreadystatechange 
    = function(){
                
    if(xmlHttp.readyState == 4){
                    
    if(xmlHttp.status == 200){
                        xmlDom 
    = getXmlDom(xmlHttp.responseText);//create xmlDom
                        
    if(xmlDom != null){
                            eval(callBack(xmlDom));
                        }
                    }
                }
            }
            xmlHttp.open(
    'Post',url,true);
            xmlHttp.setRequestHeader(
    "Content-Length",parameters.length);
            xmlHttp.setRequestHeader(
    "Content-Type","application/x-www-form-urlencoded");
            xmlHttp.send(parameters);
        }
    }

  • 相关阅读:
    表达式for loop
    用户输入
    字符编码
    变量字符编码
    Python安装
    Python 2 or 3?
    Python解释器
    2017中国大学生程序设计竞赛
    Educational Round 27
    Round #429 (Div.2)
  • 原文地址:https://www.cnblogs.com/BeanHsiang/p/1107080.html
Copyright © 2011-2022 走看看