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

  • 相关阅读:
    洛谷-P1591 阶乘数码
    洛谷-P1328 生活大爆炸版石头剪刀布
    git的使用
    docker下载命令
    springboot学习笔记
    内部类被实例化才会被加载进内存测试
    springboot环境搭建遇到的问题
    Java多线程的锁机制
    spring JdbcTemplate学习
    多线程循环注意
  • 原文地址:https://www.cnblogs.com/BeanHsiang/p/1107080.html
Copyright © 2011-2022 走看看