JS提交并解析后台返回的XML的代码

复制代码 代码如下:


<SCRIPT LANGUAGE="JavaScript">
<!--
function createRequestObject() {
try {
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); //for IE explorer
usewin = "msxml";
}
catch(e) {
try {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); //for IE
usewin = "microsoft";
}
catch(e) {
try{
xmlhttp=new XMLHttpRequest();}catch(e){} //for Mozilla
}
}
if(!xmlhttp&&typeof XMLHttpRequest!="undefined") { //object is null
xmlhttp=new XMLHttpRequest();
usewin = "undefined";
}
return xmlhttp;
}
function sendRequest() {
try{
var url="/xxxxx.xxx?para_1="xxx"&para_2="xxxx";
xmlhttp.open("GET", url, true);
xmlhttp.setRequestHeader('Content-Type', "text/xml"); //set request type (xml)
xmlhttp.onreadystatechange = handleResponse; //if state changed, function handleResponse called
xmlhttp.send(null); //send request
}
catch(e){
alert('Request send failed.');
}
finally{}
}


function handleResponse() //state changed
{
try {
if((xmlhttp.readyState == 4)&&(xmlhttp.status == 200)){ //Received success
var response = xmlhttp.responseXML.documentElement; //get response obj
var node_ = response.getElementsByTagName('user'); //example
var s="";
var grouplist=document.getElementById("guserlist");//example
var objX=null;

for(var i=0;i<node_.length;i++) {
var s1=node_[i].childNodes[0].childNodes[0].nodeValue; //id --example
var s2=node_[i].childNodes[1].childNodes[0].nodeValue; //name --example
objX=new Option(s2,s2);
grouplist.options[document.scugroupsmodform.guserlist.length]=objX;
}
}
}catch(e){
alert('Response failed.');
}
finally{}
}
//-->
</SCRIPT>


由于环境限制,只能用英文写注释 .... 原谅下...

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjzdzp.html