473,395 Members | 1,676 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,395 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);
alert(req.responseXML.xml); //this gives me the resulting xml file
} 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();
alert(req.responseXML.xml); //this gives me nothing
}
}

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 and 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 23 '05 #1
2 2504


mi**********@yahoo.com wrote:

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.


But a JSP sends an HTTP response and you simply need to make sure the
JSP sets the right HTTP response header e.g.
Content-Type: application/xml
or
Content-Type: text/xml
Ask in a JSP group on how to do that, or probably any advanced JSP
tutorial will tell you how to set the Content-Type header for the HTTP
response the JSP sends.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Can't believe that hadnt occured to me. Its now working :)

Jul 23 '05 #3

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

Similar topics

5
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...
5
by: Justice | last post by:
Currently I'm doing some experimenting with the XMLHTTP object in Javascript. Now, the XMLHttp object is asynchronous (at least in this case), and the following code causes a significant memory...
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...
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
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: 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
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
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.