ajax学习

var xmlRequest;
function ajaxForCancellMedia(barCode)
{
var url  = '<c:url value="/cancellMedia.do"/>?barCode='+barCode;
xmlRequest = getXmlHttpRequest();
xmlRequest.onreadystatechange = callbackForCancellMedia;
xmlRequest.open("POST",url,true);
xmlRequest.setRequestHeader("content-type","application/x-www-form-urlencoded;charset=UTF-8");
xmlRequest.send(null);
}

//取得AJAX的实例的公共方法
function getXmlHttpRequest()
{  
var xmlhttp;
try
{
    xmlhttp = new XMLHttpRequest();//object
}
catch(e)
{
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");//activeX
}
return xmlhttp;
}
function callbackForCancellMedia()
{  
if(xmlRequest.readyState==4)
{
if(xmlRequest.status==200)
{
paraseMessageForCancellMedia();
}else{
alert("请求失败 ,原因:"+xmlRequest.statusText);
}
}
}

function paraseMessageForCancellMedia()
{
var xmlDoc = xmlRequest.responseXML.documentElement;
if(xmlDoc!=null)
{
var node = xmlDoc.getElementsByTagName("info");
var re=node[0].firstChild.nodeValue;
if(re=="ok"){
alert("yes");
document.searchForm.submit();
}else{
alert("no");
}

}else
{
alert("程序发生内部错误!");
return;
}
}

你可能感兴趣的:(Ajax,Microsoft)