In ajax, how does one display the XML string submitted using the POST method on the server to the client? Original Code: & lt ;! DOCTYPE & nbsp; HTML & nbsp; PUBLIC & nbsp; & quot;-W3CDTD & nbsp; HTML & nbsp; 4.0 & nbsp; TransitionalEN & quot; & gt; & lt; HTML & XML string submitted using the POST method in ajax. how does the server display the string back to the client?
Original code:
New Document
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 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
Select OPtion
Server response
Test
------ Solution --------------------
Client: The following function should add Post-receipt processing.
Function show (){
If (xmlhttp. readyState = 4 ){
If (xmlhttp. status = 200 ){
Var return_value = xmlhttp. responseXML;
// Then process the returned value.
}
}
Server: in postxml. php
Output an XML format item based on the obtained parameters.
I just got in touch with it. if there is anything wrong, please forgive me.