XMLDocument and XMLHttpRequest ?

Discussion in 'Javascript' started by Jarod, Dec 29, 2005.

  1. Jarod

    Jarod Guest

    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 code... let's say it works...

    So I got serviceRequest.responseXML and is there a way to initialize xmlDoc
    in my case ? I am asking because I have code that uses xmlDoc.load(...) in
    FF and all code that's need to futher work with XML written. So this would
    be comfortable for me to use xmlDoc instead of creating everything from
    start.
    Jarod
     
    Jarod, Dec 29, 2005
    #1
    1. Advertising

  2. Jarod wrote:


    > 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 code... let's say it works...
    >
    > So I got serviceRequest.responseXML and is there a way to initialize
    > xmlDoc in my case ?


    How about
    var xmlDoc = serviceRequest.responseXML;
    Of course you have to put that in the onreadystatechange event handler
    at the proper place after a check of e.g.
    if (serviceRequest.readyState == 4)
    and perhaps further checks of the HTTP status code. But once you have
    responseXML you can use that as your XML document.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Dec 29, 2005
    #2
    1. Advertising

  3. Jarod

    VK Guest

    Martin Honnen wrote:
    > Jarod wrote:
    >
    >
    > > 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 code... let's say it works...
    > >
    > > So I got serviceRequest.responseXML and is there a way to initialize
    > > xmlDoc in my case ?

    >
    > How about
    > var xmlDoc = serviceRequest.responseXML;
    > Of course you have to put that in the onreadystatechange event handler
    > at the proper place after a check of e.g.
    > if (serviceRequest.readyState == 4)
    > and perhaps further checks of the HTTP status code. But once you have
    > responseXML you can use that as your XML document.


    And of course your server has to send *.xml files with text/xml content
    header otherwise this bird won't fly (AJAX still doesn't respect file
    extensions and your responseXML will contain an empty string).
     
    VK, Dec 29, 2005
    #3
  4. Jarod

    Guest

    VK wrote:
    > And of course your server has to send *.xml files with text/xml content
    > header otherwise this bird won't fly (AJAX still doesn't respect file
    > extensions and your responseXML will contain an empty string).


    It is my experience that you are safest sending the Content-Type as
    application/xml rather than text/xml.
     
    , Dec 29, 2005
    #4
  5. VK wrote:

    > And of course your server has to send *.xml files with text/xml
    > content [...] (AJAX still doesn't respect file extensions


    First, there is no such thing as AJAX being a defined application framework
    or something, so it does not make sense to state "AJAX does/not support
    this or that". Second, I hope "it" never will support that: "File
    extensions" are merely a Micro$~1 means to mask their ongoing inability
    to support MIME/magic properly and consequently. "File extensions" do not
    belong on today's Web.

    <URL:http://www.w3.org/QA/Tips/uri-choose> et seq.


    PointedEars
     
    Thomas 'PointedEars' Lahn, Dec 30, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shoval Tomer
    Replies:
    0
    Views:
    476
    Shoval Tomer
    Jul 9, 2003
  2. KathyB
    Replies:
    0
    Views:
    468
    KathyB
    Jul 25, 2003
  3. martin

    xmldocument &quot; and "

    martin, Mar 6, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    526
    martin
    Mar 7, 2004
  4. Bob
    Replies:
    1
    Views:
    2,727
  5. Bob
    Replies:
    0
    Views:
    435
Loading...

Share This Page