473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

XmlHTTPRequest and responseXML in IE

Been banging my head against this one for some time. I'm attempting to
use XmlHTTPRequest to read an XML document from the web server and
interact with it using the DOM. So far, I've had less than perfect luck
with IE. What I've established:

- In IE, the responseXML property sometimes returns an empty document.
- It always does so when testing on local files.
- It (sometimes? always?) works fine when pages are served by a web
server.

I saw one comment on the web explaining that it only parses the response
into a DOM in responseXML if the HTTP response's content type is
text/xml. That would kinda make sense, I guess, if I assumed that local
requests simply don't have a content type and so aren't parsed.

Anything else to watch out for? Is there a workaround to force IE to
always parse the response text, even if it doesn't happen to guess that
the format is XML?

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Jul 20 '05 #1
9 13815
On Fri, 25 Jul 2003 19:05:29 -0600, Chris Smith <cd*****@twu.net>
wrote:
Been banging my head against this one for some time. I'm attempting to
use XmlHTTPRequest to read an XML document from the web server and
interact with it using the DOM. So far, I've had less than perfect luck
with IE. What I've established:

- In IE, the responseXML property sometimes returns an empty document.
- It always does so when testing on local files.
- It (sometimes? always?) works fine when pages are served by a web
server.
Maybe you're issuing async requests (good) but not waiting until the
data is ready (bad).
I saw one comment on the web explaining that it only parses the response
into a DOM in responseXML if the HTTP response's content type is
text/xml. That would kinda make sense, I guess, if I assumed that local
requests simply don't have a content type and so aren't parsed.

Anything else to watch out for? Is there a workaround to force IE to
always parse the response text, even if it doesn't happen to guess that
the format is XML?


It's not a matter of "guessing" the format because the content-type
indentifies what the server is sending back. If you know better than
the server, then use responseText instead of responseXml and do
whatever you want with the data. You can also just forget about
XMLHTTP completely and use a DOMDocument object's load(<url>) method.

Regards,
Steve
Jul 20 '05 #2
Steve van Dongen wrote:
On Fri, 25 Jul 2003 19:05:29 -0600, Chris Smith <cd*****@twu.net>
wrote:
Been banging my head against this one for some time. I'm attempting to
use XmlHTTPRequest to read an XML document from the web server and
interact with it using the DOM. So far, I've had less than perfect luck
with IE. What I've established:

- In IE, the responseXML property sometimes returns an empty document.
- It always does so when testing on local files.
- It (sometimes? always?) works fine when pages are served by a web
server.


Maybe you're issuing async requests (good) but not waiting until the
data is ready (bad).


Nah, using synchronous requests.
Anything else to watch out for? Is there a workaround to force IE to
always parse the response text, even if it doesn't happen to guess that
the format is XML?


It's not a matter of "guessing" the format because the content-type
indentifies what the server is sending back. If you know better than
the server, then use responseText instead of responseXml and do
whatever you want with the data. You can also just forget about
XMLHTTP completely and use a DOMDocument object's load(<url>) method.


Well, the server will always report text/xml as far as I know, but IE
seems to not work with local files, which makes it a bit difficult to do
exploratory testing. Aside from that, I've just seen this thing start
and stop working enough that I'm nervous about trusting it to work in
production. I *think* I can trace times when it hasn't worked to errors
in the returned XML content, but since I've seen empty DOM documents
when the XML is fine in some scenarios (at least with local files), I'm
being skeptical.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Jul 20 '05 #3
Steve van Dongen wrote:
On Fri, 25 Jul 2003 19:05:29 -0600, Chris Smith <cd*****@twu.net>
wrote:

Been banging my head against this one for some time. I'm attempting to
use XmlHTTPRequest to read an XML document from the web server and
interact with it using the DOM. So far, I've had less than perfect luck
with IE. What I've established:

- In IE, the responseXML property sometimes returns an empty document.
- It always does so when testing on local files.
- It (sometimes? always?) works fine when pages are served by a web
server.

Maybe you're issuing async requests (good) but not waiting until the
data is ready (bad).

[...snip...: Noting that the OP responded he uses sync ... ]

Could you please give an explanation of why one should prefer async over
sync?

Thanks
Stephen

Jul 20 '05 #4
On Mon, 28 Jul 2003 02:29:44 GMT, Stephen <ss*****@austin.rr.com>
wrote:
Steve van Dongen wrote:
On Fri, 25 Jul 2003 19:05:29 -0600, Chris Smith <cd*****@twu.net>
wrote:

Been banging my head against this one for some time. I'm attempting to
use XmlHTTPRequest to read an XML document from the web server and
interact with it using the DOM. So far, I've had less than perfect luck
with IE. What I've established:

- In IE, the responseXML property sometimes returns an empty document.
- It always does so when testing on local files.
- It (sometimes? always?) works fine when pages are served by a web
server.

Maybe you're issuing async requests (good) but not waiting until the
data is ready (bad).

[...snip...: Noting that the OP responded he uses sync ... ]

Could you please give an explanation of why one should prefer async over
sync?


I should clarify that my comments are intended to be taken in the
context of client-side script running in a web page. I don't believe
there are any problems with using sync requests if you are writing
script running in ASP or WSH.

I remember reading a comment by a Microsoft program manager that he
regretted that they had ever published sample code that demonstrated
sync requests. Unfortunately he never explained the reasons behind
the comment, but this is why I say to always use async...

The big thing with sending sync requests is that your page is
basically frozen from the time that the request is sent until a
response is received. When using async, the request is sent and your
callback function is called when the server responds so that you can
process the response. In the meantime, any script you have will
continue executing, the browser is free to do whatever processing it
needs to do, and your script can respond to events.

A more obscure problem is that using sync requests can potentially
lead to deadlocks though I admit that I have no idea how likely it is.
Our group was developing an application where we kept hitting
deadlocks and it was traced to the fact that the application was using
a combination of sync and async requests. I don't know the exact
details but the problem wouldn't have happened if we had used all sync
requests or all async; it was just the combination of the two types
that caused the deadlock. The browser always makes async requests;
therefore your script should make async requests as well.

Also, you have the ability to cancel an async request. OTOH with a
sync request you have no choice but to wait for it to complete (and
hope the server isn't in a bad state which causes it to never
respond).

Regards,
Steve
Jul 20 '05 #5
Steve van Dongen wrote:
On Mon, 28 Jul 2003 02:29:44 GMT, Stephen <ss*****@austin.rr.com>
wrote:

Steve van Dongen wrote:
On Fri, 25 Jul 2003 19:05:29 -0600, Chris Smith <cd*****@twu.net>
wrote:

Been banging my head against this one for some time. I'm attempting to
use XmlHTTPRequest to read an XML document from the web server and
interact with it using the DOM. So far, I've had less than perfect luck
with IE. What I've established:

- In IE, the responseXML property sometimes returns an empty document.
- It always does so when testing on local files.
- It (sometimes? always?) works fine when pages are served by a web
server.
Maybe you're issuing async requests (good) but not waiting until the
data is ready (bad).
[...snip...: Noting that the OP responded he uses sync ... ]

Could you please give an explanation of why one should prefer async over
sync?

I should clarify that my comments are intended to be taken in the
context of client-side script running in a web page. I don't believe
there are any problems with using sync requests if you are writing
script running in ASP or WSH.

... comment by a Microsoft program manager that he
regretted ...

.. your page is basically frozen ...

.. sync requests can potentially lead to deadlocks ...

The browser always makes async requests..
yes, I believe this is the nature of HTTP

...Also, you have the ability to cancel an async request...


That seems to cover a lot of bases; thanks for the thorough response...

Stephen

Jul 20 '05 #6
Steve van Dongen wrote:
The big thing with sending sync requests is that your page is
basically frozen from the time that the request is sent until a
response is received. When using async, the request is sent and your
callback function is called when the server responds so that you can
process the response. In the meantime, any script you have will
continue executing, the browser is free to do whatever processing it
needs to do, and your script can respond to events.


Are you saying that the browser is essentially single-threaded, and if I
take a long time to return from a JavaScript function, the browser can't
do anything else in that time frame? That would be a reason to use
async requests, I suppose, but I'm appalled that it is the case.

I'm not concerned about the display of the page (which is really all
auto-generated by DHTML based on the contents of the XML file I'm
loading, anyway). However, if the browser wouldn't be able to show a
menu, or close itself, or other basic functions, that would certainly be
a pain.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Jul 20 '05 #7
Berislav Lopac wrote:
Think a little about it and all will sit perfectly. As the name implies,
XMLHTTPRequest calls a document using the HTTP protocol. When you test on
local files, you don't use the HTTP; when testing via a web server, you do.

IOW, always test with a server. It simulates the final conditions more
accurately.


Well, that would make sense if the documentation didn't explicitly say
that this class can actually issue requests over other protocols as
well. In any case, it's not the local file issue itself that concerns
me; it's the fact that there's behavior that seems to be contrary to the
documentation, and I don't feel comfortable relying on correct behavior.
I thought I'd ask here to see if anyone had a nice explanation, or
enough experience to say with confidence that this works reliably.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Jul 20 '05 #8
On Mon, 28 Jul 2003 09:10:18 -0600, Chris Smith <cd*****@twu.net>
wrote:
Are you saying that the browser is essentially single-threaded, and if I
take a long time to return from a JavaScript function, the browser can't
do anything else in that time frame?


javascript is single threaded, and it will lock the window to input
and updates while it's processing.

Which is why you don't use sync, or sleep in any event driven
environment.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #9
Jim Ley wrote:
On Mon, 28 Jul 2003 09:10:18 -0600, Chris Smith <cd*****@twu.net>
wrote:
Are you saying that the browser is essentially single-threaded, and if I
take a long time to return from a JavaScript function, the browser can't
do anything else in that time frame?


javascript is single threaded, and it will lock the window to input
and updates while it's processing.

Which is why you don't use sync, or sleep in any event driven
environment.


Okay, point taken. This resolves my concurrency concerns, I guess, in
another thread. I assume this is true between frames, not just within a
frame? If so, then I'll definitely go switch to async requests.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Marco Laponder | last post by:
Hi All, I am using XmlHttpRequest object within Firefox to get a xml document from the servlet. The reponseText is set but the responseXml is null. My Code is: req = new XMLHttpRequest();...
4
by: Rich Hephner | last post by:
I'm a rookie to XMLHttpRequest and I'm having a hard time creating an XML object that I can parse using both IE and FireFox. Works great in Firefox, but IE returns "0" for "alert(topics.length)"....
2
by: Adam | last post by:
This is frustrating me. Opening IE displays the following code fine. When I open a new window the code no longer works. All the HTML is overwritten with the first document.write statement. Tried...
3
by: joker | last post by:
Thanks in Advance. I'm trying to find out why my responseXML is empty when the Content-Type for my request is "text/xml". I'm calling into a servlet from a web page on the same domain returning...
0
by: lprisr | last post by:
Hi, With XmlHttpRequest object, using .responseText ALWAYS force the data into utf-8. I am trying to preserve encoding, so I am looking to use .responseXML. Also I am using Atlas, so I can't...
4
by: Jarod | last post by:
Hey I have something like this: var xmlDoc=document.implementation.createDocument("", "", null); but in opera xmlDoc.load(...) won't work, so I use: XMLHttpRequest, and I have all needed...
27
by: ted benedict | last post by:
hi everybody, i hope this is the right place to discuss this weird behaviour. i am getting dynamically generated text or xml from the server side using xmlhttprequest. if the server side data is...
8
dmjpro
by: dmjpro | last post by:
i m generating a xml file through jsp file using AJAX. my response header in jsp file is like this .. <%@ page contentType = "text/xml;charset = WINDOWS-1252"%> when i do...
7
RMWChaos
by: RMWChaos | last post by:
Bizarro, that's all I can say. Aren't FF2.0.0.8 and NN9 both Mozilla 2 based browsers? So why would the exact same code work in one and not the other? To add insult to injury, it works just fine in...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.