做一个最简单的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);
    }
}

相关文章:

  • 2020-05-18
  • 2022-12-23
  • 2021-08-20
  • 2021-06-17
  • 2022-12-23
  • 2022-12-23
  • 2021-09-27
  • 2021-12-02
猜你喜欢
  • 2021-11-13
  • 2021-12-15
  • 2021-08-04
  • 2021-02-27
  • 2022-12-23
相关资源
相似解决方案