1 Reply Latest reply on May 8, 2009 2:06 PM by Nick Belaevski

    XMLHttpRequest accept header browser issue and XML parse err

    Mike Hanafey Newbie

      Apparently the default request "accept" header for XMLHttpRequest is different in Firefox 3, IE, and Chrome, and this is at the root of parse errors in AJAX response with JSF Mojarra if one runs with filter NONE.

      Specifically, Firefox 3 has "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" as the accept header, but IE and Chrome have "*/*". This causes XML parse errors for the IE and Chrome browsers, but Firefox works fine.

      Firefox works fine only if the context init parameter "com.sun.faces.preferXHTML" is set true. Mojarra uses this to set the contentType of the generated response. Without the context parameter true Mojarra chooses "text/html" for Firefox (it is first in the accept header), but when XHTML is specified it chooses "application/xhtml+xml". This impacts the way JavaScript is escaped in the response, and improper escaping is what causes the XML parse error.

      UNFORTUNATELY, with accept set to "*/*", Mojarra is pretty stupid, and even with "preferXHTML" set true it returns "text/html" as the content type https://javaserverfaces.dev.java.net/issues/show_bug.cgi?id=1106.

      HOWEVER, this is the default accept header for XMLHttpRequest, and it seems that RichFaces could explicitly set request header accept to "application/xhtml+xml", and this would solve the problem for all browsers, and then the "com.sun.faces.preferXHTML" init parameter would not even be needed.