A collection of common problems in Ajax program development
Author:Eve Cole
Update Time:2009-07-06 16:35:51
1. When the format of the xml document returned by response in ajax or action is wrong, eclipse debug cannot enter the action.
2. Ajax caching problem needs to be solved by adding xmlHttp.setRequestHeader("If-Modified-Since", "0");.
3. If it is not submitted by ajax, but PrintWriter out = response.getWriter(); is set, the jsp will generate Chinese garbled characters.
4. The reason why ajax returns garbled xml code
response.setContentType("text/xml;charset=GBK");
PrintWriter out = response.getWriter();
This will only work if:
PrintWriter out = response.getWriter();
response.setContentType("text/xml;charset=GBK");
Then response.setContentType("text/xml;charset=GBK"); will not work, so the returned code will be garbled. This problem has been going on for a long time, and the code needs to be looked at carefully.
5.ajax form submission
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
Since what is passed is UTF-8 encoded, it needs to be transcoded accordingly when it is accepted in an action or servlet.