| 1. |
What Do I Do On The Server To Interact With An Ajax Client? |
|
Answer» The "Content-Type" header needs to be set to"text/xml". In servlets this may be done using the HttpServletResponse.setContentType()should be set to "text/xml" when the return type is XML. Many XMLHttpRequest IMPLEMENTATIONS will RESULT in an error if the "Content-Type" header is set The code below shows how to set the "Content-Type". response.setContentType("text/xml");response.getWriter().write("<response>invalid</response>"); You may also want to set whether or not to set the caches header for cases such as autocomplete where you may want to notify proxy servers/and browsers not to cache the results. response.setContentType("text/xml");response.setHeader("Cache-Control", "no-cache"); response.getWriter().write("<response>invalid</response>"); Note to the developer: Internet Explorer will automatically use a cached result of any AJAX response from a HTTP GET if this header is not set which can make THINGS difficult for a developer. During development mode you may want set this header. Where do I store state with an AJAX client
The "Content-Type" header needs to be set to"text/xml". In servlets this may be done using the HttpServletResponse.setContentType()should be set to "text/xml" when the return type is XML. Many XMLHttpRequest implementations will result in an error if the "Content-Type" header is set The code below shows how to set the "Content-Type". You may also want to set whether or not to set the caches header for cases such as autocomplete where you may want to notify proxy servers/and browsers not to cache the results. Note to the developer: Internet Explorer will automatically use a cached result of any AJAX response from a HTTP GET if this header is not set which can make things difficult for a developer. During development mode you may want set this header. Where do I store state with an AJAX client |
|