XMLHTTP and DOMDocument Using Problem in Web App Select BLOG's Blog using XMLHTTP to achieve new data for new automatic access server in the page, and you can realize new data in some chat rooms, you can also Timed new page data is realized in other BS applications. However, some problems will be encountered when using XMLHTTP and DomDocument. One is how to transfer parameters, and the second is Chinese garbled problems, and there is how to resolve XML code. 1. Parameter Transfer and Get Parameter Values XMLHTTP's Send Method Send (Varbody) Varbody: Instruction Set. Can be XML format data, or a string, stream, or an unsigned integer array. It can also be omitted, and the instruction will be submitted through the URL parameter of the OPEN method. The Send method can also transmit parameters pairs, and each parameter can be used with & separation, such as VAR post = "ID = 1000 & Page = 3"; XMLHttp.send (POST); or join on the URL parameter of the Open method, such as XMLHTTP .open ("post", "http: // localhost: 8088 / getData? id = 1000 & page = 3", false); In JSP or servlet, you can get a parameter string id = (String) from the request in peacetime. Req.getParameter ("ID"); string page = (string) Req.getParameter ("Page"); because the request sent by XMLHTTP is not the Multipart / Form-Data format, it is not possible to use multiple formats in Multipart / Form-Data format. Some methods.
2, Chinese garbled problem XMLHTTP is sent to request and receive return values in UTF-8, so if there is no coding process, in the transmission of the parameters or in the received return value, then we see It is garbled to handle the parameters sent by the sending VAR post = "years = 2004-2005 & termid = autumn and winter"; // contains Chinese XMLHttp.Open ("post", "http: // localhost: 8088 / getData", false); XMLHTTP .SetRequestHeader ("Content-Type", "Application / X-WWW-Form-Urlencoded"); // To have this sentence xmlhttp.setrEquestHeader ("Content-length", post.length; xmlhttp.send (POST); When the parameter is taken in the servlet, the Request is encoded to process Req.SetCharacterencoding ("UTF-8"); then take the parameter string years = (string) Req.getParameter ("years"); string termid = (String) Req.getParameter ("Termid"); if there is a page with output data to the requested page in the servlet, if you include Chinese, you should first encode the response to encode the response to process private static final string content_type = "text / html; charset = UTF- 8 "; res.setContentType (content_type); use UTF-8 in the output XML code (" Xml version = / "1.0 /" encoding = / "UTF-8 /" Standalone = / " YES / "?>"); out.println ("