• 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

responseXML in JavaScript

 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is Simple.xml...

In the same directory as Simple.xml, I have an html file running the following JavaScript snippet...

But the collection of elements has a length of zero. I'm sure it's something stupid, but what am I doing wrong here?
[ March 20, 2008: Message edited by: marc weber ]
 
Sheriff
Posts: 67748
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 not waiting for the Ajax request to return the response. You'll need to read the parsed XML in the ready state callback once the response is returned successfully.
[ March 20, 2008: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Sheriff
Posts: 67748
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
I've said it before and I'll say it again: in this day and age, writing Ajax "by hand" is akin to hitting yourself in the middle of the forehead with a ball-peen hammer. Sure, you can do it. But why would you?

However, to get Ajax concepts under your belt (also not a bad idea), I suggest this article.
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Bear!

My experience with JavaScript is close to zero. I'm just trying to repair someone else's code and learn something along the way.

Unfortunately, now that I'm home using a Mac, I can't reproduce the problem -- it works fine in Safari using an XMLHttpRequest instead of ActiveXObject. But using IE earlier, I displayed the readyState before trying to get the responseXML, and it showed 4...

But in reviewing the link you provided, I noticed the following...

It is essential that the data returned from the server be sent with a Content-Type set to text/xml. Content that is sent as text/plain or text/html is accepted by the instance of the request object however it will only be available for use via the responseText property.


I was experimenting with all of this while my server was down for maintenance, so my html and xml files were just on my C-drive -- not a server. So my guess is that the Content-Type was messing things up. Does that make sense? Or am I still missing something with the readyState?
 
Bear Bibeault
Sheriff
Posts: 67748
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 marc weber:
[QB]I displayed the readyState before trying to get the responseXML, and it showed 4...[/q]

Ah yes, I hadn't noticed that you set the async flag to false. That causes the code to block until done. (Not usually encouraged).

So my guess is that the Content-Type was messing things up

That woudl be what I'd focus on next.
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Bear!

After reading up a bit, I did set the async flag to true, and I've written a function that's triggered by onreadystatechange. I'm finally able to get the responseXML to dig through.

(The actual xml file is a Notes page pieced together using computed text and embedded views, but the content type is set for "text/xml," so that's working okay now that the server is back up.)
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, it's all good now. It even works with WebSEAL, unlike the vendor's original code.

Thanks!
 
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic