在ajax中用POST方法提交的XML串,服务器端如何回显到客户端?
符上原代码:
nbsp; HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN ">
New Document <script> <br /> var xmlhttp; <br /> function createXmlRequest(){ <br /> if(window.ActiveXObject){ <br /> xmlhttp=new window.ActiveXObject( "Microsoft.XMLHTTP "); <br /> }else{ <br /> if(window.XMLHttpRequest){ <br /> xmlhttp=new XMLHttpRequest(); <br /> }else{ <br /> alert( "error "); <br /> } <br /> } <br /> var url= "postxml.php? "+new Date().getTime(); <br /> xmlhttp.open( "POST ",url,true); <br /> xmlhttp.setRequestHeader( "Content-Type ", "application/x-www-form-urlencoded; "); <br /> xmlhttp.onreadystatechange=show; <br /> xmlhttp.send(createXml()); <br /> } <br /> function createXml(){ <br /> var xml= " <pets> "; <br /> var options=document.getElementById( "petTypes ").childNodes; <br /> var option=null; <br /> for(var i=0;i <options.length;i++){ <br /> option=options[i]; <br /> if(option.selected){ <br /> xml=xml+ " <type> "+option.value+ " "; <br /> } <br /> } <br /> alert(xml+ " "); <br /> return xml+ " "; <br /> <br /> } <br /> function show(){ <br /> if(xmlhttp.readyState==4){ <br /> if(xmlhttp.status==200){ <br /> var response=document.getElementById( "response "); <br /> if(response.hasChildNodes()){ <br /> response.removeChild(response.childNodes[0]); <br /> } <br /> document.getElementById( "response ").appendChild(document.createTextNode(xmlhttp.responseText)); <br /> } <br /> } <br /> } <br /> </script>
select OPtion
Server response
test
------解决方案--------------------客户端:下面这个函数里面应该添加接收后的处理.
function show(){
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
var return_value = xmlhttp.responseXML;
//然后你再对返回的这个值进行处理.
}
}
服务器端:postxml.php中
根据你所获取的参数进行输出一个XML格式的东西.
我也是刚接触.如有不对,敬请谅解.