Howto access xmlHttp.responseText as document.getElementByTagName, etc...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • marcus6
    New Member
    • Apr 2006
    • 4

    Howto access xmlHttp.responseText as document.getElementByTagName, etc...

    Howto access xmlHttp.respons eText as document.getEle mentByTagName ?

    If I access a .html page through the xmlHttp, how can I use the functions .getElementsByT agName and .getElementById on the data found in the xmlHttp.respons eText?

    (the .responseXML returns null, and the responseText is simple text, of course containing valid html code)
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Either have valid XML or you could add it to the document e.g. a hidden div and then parse it.

    Comment

    • ronnil
      Recognized Expert New Member
      • Jun 2007
      • 134

      #3
      Originally posted by marcus6
      Howto access xmlHttp.respons eText as document.getEle mentByTagName ?

      If I access a .html page through the xmlHttp, how can I use the functions .getElementsByT agName and .getElementById on the data found in the xmlHttp.respons eText?

      (the .responseXML returns null, and the responseText is simple text, of course containing valid html code)
      What I'm reading:

      You want to download an html page via xmlHttp, the elements inside that that downloaded html page you want to access via document.getEle mentByID

      right?

      This is not doable, per say, since you don't download htmlpages with htmlHttp but you download data, either in string or xml.

      What i think acoder means is:

      you make an empty div tag.
      you download your htmlpage and retrieve it with the responseText property.
      you then set your div tag's innerHTML=respo nseText

      now, for browser compability reasons i suggest you use an iframe instead of a div tag :) for example, if your html page is valid xhtml you will have header and such defined, that could make browsers confused... this won't happen in an iframe ;)

      Comment

      • marcus6
        New Member
        • Apr 2006
        • 4

        #4
        Actually I wanted to download a html template and an xml file and combine them in the browser :P I don't know if this is a good idea, but I guess it could be done.

        Now I need to mostly replace the actual page in the browser with the one downloaded and then fill it wit data from the xml.

        Gimme your critics on this idea :)

        Comment

        • rnd me
          Recognized Expert Contributor
          • Jun 2007
          • 427

          #5
          Originally posted by marcus6
          Actually I wanted to download a html template and an xml file and combine them in the browser :P I don't know if this is a good idea, but I guess it could be done.

          Now I need to mostly replace the actual page in the browser with the one downloaded and then fill it wit data from the xml.

          Gimme your critics on this idea :)
          yes, it is a good idea.
          so good that there is already a major system for doing just that:
          XSLT.

          think of it as CSS on steroids.

          you can not only apply html styles to the xml data, but you can sort, filter, modify, combine severy files, etc.

          be sure read up on it, it sound like it would be right up your alley.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by ronnil
            What i think acoder means is:

            you make an empty div tag.
            you download your htmlpage and retrieve it with the responseText property.
            you then set your div tag's innerHTML=respo nseText
            Yes, that's right.
            Originally posted by ronnil
            now, for browser compability reasons i suggest you use an iframe instead of a div tag :) for example, if your html page is valid xhtml you will have header and such defined, that could make browsers confused... this won't happen in an iframe ;)
            Yes, that's a better solution. Thanks!

            Comment

            Working...