Javascript XMLResponse returning null

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aaronharwood
    New Member
    • Jul 2010
    • 2

    Javascript XMLResponse returning null

    I have read dozens of existing responses on threads, that span the last 5 years or so, concerning this problem and while there are many solutions that appear to work for others - none work for me.

    I have some Javascript that is receiving an XML file from a Servlet. The problem is that the XMLResponse always returns a null value.

    Here is some the code snippet:

    Code:
    ...
    function alertContents() {
       if (http_request.readyState == 4) {
          if (http_request.status == 200) {	 
        	 alert(http_request.readyState);
        	 alert(http_request.status);
        	 alert(http_request.getAllResponseHeaders()); 
        	 alert(http_request.responseText);
        	 alert(http_request.responseXML);
    ...
    The alerts give the following outputs.

    4

    200

    Date: Sat, 03 Jul 2010 08:44:44 GMT
    Content-Length: 271
    Server: Apache-Coyote/1.1
    Content-Type: text/xml;charset=ISO-8859-1

    <?xml version="1.0" encoding="UTF-8" standalone="no" ?><Console ConsoleType="Er rorConsole"><Co nsoleName>Serve r Error</ConsoleName><Er rorMessage>The Console servlet requires a consoleType parameter. This parameter was not found in the URL request.</ErrorMessage></Console>

    null

    As you can see, the content type iss text/xml. Pasting the XML into a validator gives a valid response. I really have no idea why the XMLResponse is returning null - there doesn't appear to be any reason to fail.

    Using IE, the errorCode is 0, so there is no help there.

    There does not appear to be any other way to debug this.

    Any suggestions?
    Last edited by Dormilich; Jul 5 '10, 06:04 AM. Reason: Please use [code] tags when posting code
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Check out the XMLHttpRequest responses in Firebug (Firefox Add-on).
    Last edited by Dormilich; Jul 8 '10, 10:31 PM.

    Comment

    • aaronharwood
      New Member
      • Jul 2010
      • 2

      #3
      I found the problem - somewhere else in the script, before the request is made, there is a line that was forcing the mime type to be interpreted as text/html regardless of what the returned mime type was declared as. Removing that line fixed the problem.

      Comment

      Working...