File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes AJAX request.responseXML is empty Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "AJAX request.responseXML is empty" Watch "AJAX request.responseXML is empty" New topic
Author

AJAX request.responseXML is empty

Rahul Vaids
Greenhorn

Joined: Jun 23, 2008
Posts: 7
I am having an issue with the IE version not recognizing an XML par and allowing me to manipulate using DOM.I have set the conent type to tex/HTML on the resource providing me with this XML.When I see the responseText, I can clearly see my XML using alert, but when I do :

I would appreciate if someone knows what's wrong in here.Thanks a bunch.

[eric - added code tags so it is pretty]
[ June 24, 2008: Message edited by: Eric Pascarello ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61762
    
  67

tex/HTML

Not correct. tex is not even valid. Use "text/xml".


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Look at these debugging steps and see if it helps: http://radio.javaranch.com/pascarello/2006/09/12/1158096122600.html
[ June 24, 2008: Message edited by: Eric Pascarello ]
Rahul Vaids
Greenhorn

Joined: Jun 23, 2008
Posts: 7
Sorry about the typo in my original post...Eric, I tried all the steps mentioned in your website...The xml is well formed for sure bu still no luck.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61762
    
  67

Did you fix the content type?
Rahul Vaids
Greenhorn

Joined: Jun 23, 2008
Posts: 7
It was and is set in my jsp as <%@page contentType="text/xml" %>

Thanks.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
If you do



are you getting an object or null?

If an object what does this return?



Do you see the tags?


If so you might be referencing a whitspace node. [What browser is this happening in?]



If you use Firefox. The Firebug plug-in would be very handy in debugging this. Store the response in a global variable and use the console command line to test out commands.

Eric
Rahul Vaids
Greenhorn

Joined: Jun 23, 2008
Posts: 7
Alert of resp gives me [object]

alert("length is "+resp.getElementsByTagName('vehicles').length); gives me 0

alert(resp.getElementsByTagName('vehicles')[0].innerHTML); gives me JS error saying Object required.

I'm using IE version 7
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61762
    
  67

You're using a JSP? My next guess would be that some whitespace is being included before the <?xml?> declaration.
Rahul Vaids
Greenhorn

Joined: Jun 23, 2008
Posts: 7
The below code is writen in an HTML file.


As you can see, the function getData() is referencing a jsp file which has code to lookup an XML and return the XML. I have made sure now that there is no space either before the XML prolog. Unfortunately, no luck yet. I appreciate you being able to reply promptly.
[ June 25, 2008: Message edited by: Rahul Vaids ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61762
    
  67

Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and many people that might be able to help you will just move along. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61762
    
  67

Originally posted by Rahul Vaids:
I have made sure now that there is no space either before the XML prolog.

How?

Maybe it's time to show us the JSp that generates the XML. (Use code tags). I'm still betting that there's at least a newline being generated.
Rahul Vaids
Greenhorn

Joined: Jun 23, 2008
Posts: 7
Here's the JSP code:
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61762
    
  67

Yup. there's going to be a bunch of newlines in your output because of the JSP. Remember a JSP is just a template for an HTML file. So not only will this not work for you , because it will preserve all whitespace including newlines, but the fact that there is just Java code in your JSP is rather a misuse of the mechanism.

Since there is only Java code in this, why is it not a servlet where you have much finer control over what it is emitted?

P.S. For more information on the whitespace issue with JSP, see this article.
Rahul Vaids
Greenhorn

Joined: Jun 23, 2008
Posts: 7
This is being done because of a constraint in the application to not have any .java class. Hence using a JSP to achieve the functionality. Is there a was I can get rid of the white spaces?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61762
    
  67

Why the restriction? It sounds rather silly on the surface. And your JSP gets turned into a Java class, so your app has Java classes in any case.

Another question, why aren't you just referencing the XML directly? It looks like all you are doing is to stream the XML file that's under WEB-INF as the response. Why the middle man? Can you not just move the XML file out of WEB-INF and address it directly?

You might be able to reformat the JSP to emit no whitespace before the xml directive (by putting all that JSP elements on a single line) but that's really fragile.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: AJAX request.responseXML is empty