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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mikeyjudkins@yahoo.com

    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.XMLHT TP 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
    setRequestHeade r 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.XMLHttp Request) {
    // branch for native XMLHttpRequest object - THIS WORKS
    req = new XMLHttpRequest( );
    req.overrideMim eType("text/xml");
    req.onreadystat echange = processReqChang e;
    req.open("GET", "models.jsp?cId =300006&mId=TAC 24", true);
    req.send(null);
    alert(req.respo nseXML.xml); //this gives me the resulting xml file
    } else if (window.ActiveX Object) {
    // branch for IE/Windows ActiveX version - NOT WORKING
    req = new ActiveXObject(" Microsoft.XMLHT TP");
    if (req) {
    req.onreadystat echange = processReqChang e;
    req.open("GET", "models.jsp?cId =300006&mId=TAC 24", true);
    req.setRequestH eader("Content-Type","text/xml");
    req.send();
    alert(req.respo nseXML.xml); //this gives me nothing
    }
    }

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



    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 overrideMimeTyp e() 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

  • Martin Honnen

    #2
    Re: How to read dynamically generated XML with Javascript and ActiveXXMLHTTP object?



    mikeyjudkins@ya hoo.com wrote:

    [color=blue]
    > 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.[/color]

    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

    Comment

    • mikeyjudkins@yahoo.com

      #3
      Re: How to read dynamically generated XML with Javascript and ActiveX XMLHTTP object?

      Can't believe that hadnt occured to me. Its now working :)

      Comment

      Working...