在ajax中用POST方法提交的XML串,服务器端如何回显到客户端?
符上原代码:
<meta NAME= “Generator ” CONTENT= “EditPlus “>
<meta NAME= “Author ” CONTENT= ” “>
<meta NAME= “Keywords ” CONTENT= ” “>
<meta NAME= “Description ” CONTENT= ” “>
<script>
var xmlhttp;
function createXmlRequest(){
if(window.ActiveXObject){
xmlhttp=new window.ActiveXObject( “Microsoft.XMLHTTP “);
}else{
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}else{
alert( “error “);
}
}
var url= “postxml.php? “+new Date().getTime();
xmlhttp.open( “POST “,url,true);
xmlhttp.setRequestHeader( “Content-Type “, “application/x-www-form-urlencoded; “);
xmlhttp.onreadystatechange=show;
xmlhttp.send(createXml());
}
function createXml(){
var xml= ” “;
var options=document.getElementById( “petTypes “).childNodes;
var option=null;
for(var i=0;i <options.length;i++){
option=options[i];
if(option.selected){
xml=xml+ ” “+option.value+ ” “;
}
}
alert(xml+ ” “);
return xml+ ” “;
}
function show(){
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
var response=document.getElementById( “response “);
if(response.hasChildNodes()){
response.removeChild(response.childNodes[0]);
}
document.getElementById( “response “).appendChild(document.createTextNode(xmlhttp.responseText));
}
}
}
</script>
<body>
select OPtion
afds
子子子
cccc
声东击西test
Server response
——解决方案——————–
客户端:下面这个函数里面应该添加接收后的处理.
function show(){
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
var return_value = xmlhttp.responseXML;
//然后你再对返回的这个值进行处理.
}
}
服务器端:postxml.php中
根据你所获取的参数进行输出一个XML格式的@本文9来源gao($daima.com搞@代@#码8网^搞代gaodaima码东西.
我也是刚接触.如有不对,敬请谅解.