Every time I develop Ajax, I often encounter a problem where Ajax is useless. I have checked the code several times and found that there is nothing wrong with it. I usually lost the key code. The code that is often ignored is:
Ignore in HTML documents:
<! Doctype HTML>
Or
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
It should be noted that there are many Java Web-related books on the market, and the above Code is ignored when I explain Ajax. If you use IE7 or earlier versions, it will be okay. If you run on the IE 8 browser, the situation will be different. Without the above Code, Ajax calls will sometimes work and sometimes work.
Ignore in servlet:
Response. setcontenttype ("text/html ");
At this time, AJAX can submit the request to the server-side servlet, but it is not necessary to determine whether the servlet response value can be correctly received. Generally, the response data of the server must be processed in the specified callback function. The received value may be null because you ignore the previous line of code.