日期:2014-05-16 浏览次数:20454 次
<textarea name="xmls" cols="38" rows="12" id="xmls" > <?xml version="1.0" encoding="UTF-8"? > <svc_result ver="1.0.0"> <slia ver="1.0.0"> <action>testing </action> </slia> </svc_result > </textarea > <input value="提交" type="button" onclick="submiter();"/ > <script language="javascript" > //获取表单中的XML文档 //提交给testSSS.asp,同时获取返回值 //再把返回值填写到表单中 function submiter(){ //获取表单中的XML var xml; xml = document.getElementById("xmls").value; //构造url var url; url = "testSSS.asp"; //调用提交函数 //并获取返回的XML sendXML(url,xml); } </script >
function sendXML(url,xml){
var subURL;
subURL = url+"?xml="+xml;
var xmlobj;
xmlobj=createxmlhttp();
xmlobj.open("post",subURL, true);
var rsText;
rsText = "Nothing";
xmlobj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlobj.onreadystatechange=function (){
if (xmlobj.readyState==4){
if(xmlobj.status==200){
sendXML.rsText = xmlobj.responseText;
alert(sendXML.rsText);//这里弹出的是responseText值
//rsText = xmlobj.responseText;//这种办法也测试过,效果一样
//alert(rsText);
}
}
};
xmlobj.send(null);
alert(rsText);//这里就变成了修改前的值:“Noting”
return rsText;
}
function createxmlhttp()
{
//create xmlhttp object
xmlhttpobj = false;
try{
xmlhttpobj = new XMLHttpRequest;
}catch(e){
try{
xmlhttpobj=new ActiveXObject("MSXML2.XMLHTTP");
}catch(e2){
try{
xmlhttpobj=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e3){
xmlhttpobj = false;
}
}
}
return xmlhttpobj;
}
<?xml version="1.0" encoding="UTF-8"? > <svc_result ver="1.0.0" > <slia ver="1.0.0" > <action >back XMLS </action > </slia > </svc_result >