JavaScript异步获取数据解析

<script type="text/javascript">
    var xhr=false;
    function createXhr() {
    var xhobj = false;
    try {
        xhobj = new ActiveXObject("Msxml2.XMLHTTP"); // ie msxml3.0+
    } catch (e) {
        try {
            xhobj = new ActiveXObject("Microsoft.XMLHTTP"); //ie msxml2.6
        } catch (e2) {
            xhobj = false;
        }
    }
    if (!xhobj && typeof XMLHttpRequest != 'undefined') {// Firefox, Opera 8.0+, Safari
        xhobj = new XMLHttpRequest();
    }
    return xhobj;
}
     
    function doDel(du,ot,id){
    //当执行删除时候创建异步对象
    xhr=createXhr();
        if(confirm("您确定要删除此地址吗?")){
            //设置异步请求的参数(传值方式类型,du--default是否默认&ot--ordertype账户类型&aid地址编号,是否执行异步)
            xhr.open('get','DoDelAdd.ashx?Du='+du+'&Ot='+ot+'&aid='+id,true);
            //清除缓存(设置get请求不用缓存)
            xhr.setRequestHeader("If-Modified-Since","0");
            //设置回调函数
            xhr.onreadystatechange=function(){
                //检查准备状态 0--未初始化,1--载入,2--载入完成,3-正在交互,4--完成交互
                if(xhr.readyState==4){
                    //通信成功
                    if(xhr.status==200){
                        //获得返回值
                        var res=xhr.responseText;
                        //判断
                        if(res=="OK"){
                            //获取要删除行的id
                            var nowtr=document.getElementById("mrdz1"+id);
                            nowtr.parentNode.removeChild(nowtr);
                        }
                    }
                }
            }
            xhr.send(null);
        }
    }
    </script>

上一篇:Unity3D项目优化(转)


下一篇:如何移动 nuget 缓存文件夹