473,394 Members | 1,769 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,394 software developers and data experts.

How to read dynamically generated XML with Javascript and ActiveX XMLHTTP object?

Ive been banging my head on the wall for hours with this one, hopefully
someone will know what Im doing wrong here :\

The Goal:
I have an xml file that is generated on the fly via JSP which I want to
load into a Microsoft.XMLHTTP ActiveX object and manipulate via
javascript on the client side. Data is retreived from the server at the
request of the javascript without having to reload the page.

The Problem:
For the JSP to dynamically output xml, the file must have the extension
JSP, which is set to the mime type of dynamo-internal/html on the
server side (as we are using ATG Dynamo). But the javascript on the
client side will not retrieve anything unless the file extension is
..xml (or the mime type is recognized as text/xml). So the only way I
can get it to work is to change the extension to .xml, which then of
course amkes it so that the server will not process any of the JSP
code.

Ive tried to override the mime type within the javascript, using the
setRequestHeader method after opening the file, but no luck. A call to
alert the value of req.responseXML.xml after the send() turns up empty.
Ive only gotten it to work if I use a static xml file in palce of the
jsp. Sample of the javascript code is below:

if (window.XMLHttpRequest) {
// branch for native XMLHttpRequest object - THIS WORKS
req = new XMLHttpRequest();
req.overrideMimeType("text/xml");
req.onreadystatechange = processReqChange;
req.open("GET", "models.jsp?cId=300006&mId=TAC24", true);
req.send(null);
} else if (window.ActiveXObject) {
// branch for IE/Windows ActiveX version - NOT WORKING
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", "models.jsp?cId=300006&mId=TAC24", true);
req.setRequestHeader("Content-Type","text/xml");
req.send();
}
}

In looking at the following example the Microsoft gives (bottom of
page):

http://support.microsoft.com/default...;EN-US;Q290591

I just dont see what could be going wrong here.
I should note that I successfully got the script to work using the
XMLHttpRequest object and the overrideMimeType() method. This works
with FireFox adn I think some Mozilla clients, but not with the all
important IE5, which instead uses the XMLHTTP ActiveX control.

Thanks for any help,

Mike

Jul 20 '05 #1
5 8522
/mi**********@yahoo.com/:
The Problem:
For the JSP to dynamically output xml, the file must have the extension
JSP, which is set to the mime type of dynamo-internal/html on the
server side (as we are using ATG Dynamo). But the javascript on the
client side will not retrieve anything unless the file extension is
.xml (or the mime type is recognized as text/xml). So the only way I
can get it to work is to change the extension to .xml, which then of
course amkes it so that the server will not process any of the JSP
code.
Probably not that XML specific, but you should set the
'Content-Type' response header in your JSP, always:

http://java.sun.com/j2ee/1.4/docs/tu...5.html#wp73360

If you further wish the request URL to end with ".xml", the
JavaServlet specification describes how conforming containers could
be configured (web.xml - mappings between request URLs and
servlets/JSPs). Consult with your Dynamo documentation to see how
it's done there.
Ive tried to override the mime type within the javascript, using the
setRequestHeader method after opening the file, but no luck. A call to
alert the value of req.responseXML.xml after the send() turns up empty.


I have no experience with the 'XMLHttpRequest' object but I don't
think setting a request header could change the response (generated
by the server) in any way.

--
Stanimir
Jul 20 '05 #2
It worked after I changed the response header from within the JSP page.
Cant beleive I hadnt thought of that earlier!

Jul 20 '05 #3
mi**********@yahoo.com wrote:
The Problem:
For the JSP to dynamically output xml, the file must have the extension
JSP, [....] But the javascript on the
client side will not retrieve anything unless the file extension is
.xml (or the mime type is recognized as text/xml).


In addition to what's been suggested with regards to your specific
problem (set Content-Type response header), you may also want to have a
look at the classic "Cool URLs Don't Change"
<http://www.w3.org/Provider/Style/URI.html> on why file extensions in
URLs are a Bad Thing.

Regards,
Diego Berge.

--
e-mail address invalid, please reply to newsgroups.

Jul 20 '05 #4

mi**********@yahoo.com Wrote:
It worked after I changed the response header from within the JSP page.
Cant beleive I hadnt thought of that earlier!

I have the same problem in reading the XML file in IE. I use exactly
the same code, but doesn't work. WHat you mean you change the response
header from within the JSP page? (is JSP refer to JavaScript, btw?)

Thanks,
--
masantra
------------------------------------------------------------------------
masantra's Profile: http://www.24help.info/member.php?userid=450
View this thread: http://www.24help.info/showthread.php?t=347535

24help.info - IT Newsgroups @ http://www.24help.info

Sep 27 '05 #5


masantra wrote:
I have the same problem in reading the XML file in IE. I use exactly
the same code, but doesn't work. WHat you mean you change the response
header from within the JSP page? (is JSP refer to JavaScript, btw?)


If you have a server side application (e.g. CGI, ASP, JSP, PHP)
dynamically generating XML then make sure you set the HTTP response
header to application/xml or some other XML MIME type so in PHP you would do
header('Content-Type: application/xml');
before sending the XML, in ASP
Response.ContentType = "application/xml"

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 28 '05 #6

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

Similar topics

6
by: George Hester | last post by:
This location has a parasite checker using javascript. It is in a js file called parasite.js. It is freely available. http://www.doxdesk.com/parasite/ He\She is the only one I trust on the...
2
by: mikeyjudkins | last post by:
Ive been banging my head on the wall for hours with this one, hopefully someone will know what Im doing wrong here :\ The Goal: I have an xml file that is generated on the fly via JSP which I...
4
by: Guillaume CABANAC | last post by:
Hi everybody, Does anybody know how to access a remote database (say Oracle) from JavaScript code (within a Firefox Extension) ? I know ADO via ActiveX in the IE world and think a similar...
0
by: Kunal | last post by:
Hi all, I have run into a problem that I can't quite figure out. Here is the situation: I have to capture a signature from a WebForm. (The ASP.NET application is running on a TabletPC) ...
0
by: bcox | last post by:
I would like to be able to set parameter values for an ActiveX control hosted on an ASP.NET .aspx page from a C# code behind file. The ActiveX registration code is contained in <OBJECT></OBJECT>...
1
by: ozzy.osborn | last post by:
Hello All, I have been struggling with a cross browser solution to loading external javascript files on the fly. I have been successful using the following code in IE6: var newScr =...
21
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays...
3
by: VK | last post by:
On Apr 21, 1:54 pm, joe <m...@invalid.comwrote: http://www.jibbering.com/faq/index.html#FAQ4_18
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.