• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

AJAX request.responseXML is empty

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tex/HTML


Not correct. tex is not even valid. Use "text/xml".
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you fix the content type?
 
Rahul Vaids
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It was and is set in my jsp as <%@page contentType="text/xml" %>

Thanks.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're using a JSP? My next guess would be that some whitespace is being included before the <?xml?> declaration.
 
Rahul Vaids
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the JSP code:
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic