|
復制代碼 代碼如下:
<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"¶_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>
由于環(huán)境限制,只能用英文寫注釋 .... 原諒下...
JavaScript技術:JS提交并解析后臺返回的XML的代碼,轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。