The XML string submitted using the POST method in ajax. how does the server return to the client?
Source: Internet
Author: User
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;-// W3C // DTD & nbsp; HTML & nbsp; 4. in ajax, how does one display the XML string submitted using the POST method on the server 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.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.