Connecting Tech Pros Worldwide Forums | Help | Site Map

Reading part of contents from other page via XMLHttpRequest

JP
Guest
 
Posts: n/a
#1: May 13 '06
Hello,

I am trying to figure out how can I read particular content of the page
after I have requested page into XMLHttpRequest object.
Is there a way to parse somehow responseText? In pseudo code I want to
do something like this.

var myHeader = myXMLHttpRequest.document.getElementById("Header") ;


Martin Honnen
Guest
 
Posts: n/a
#2: May 14 '06

re: Reading part of contents from other page via XMLHttpRequest




JP wrote:
[color=blue]
> I am trying to figure out how can I read particular content of the page
> after I have requested page into XMLHttpRequest object.
> Is there a way to parse somehow responseText? In pseudo code I want to
> do something like this.
>
> var myHeader = myXMLHttpRequest.document.getElementById("Header") ;[/color]

If you load an XML document then you have
myXMLHttpRequest.responseXML
as a document and you can use the W3C Core DOM on that. getElementById
in XML documents works only if the document type definition defines
attributes of type ID.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Vic Sowers
Guest
 
Posts: n/a
#3: May 14 '06

re: Reading part of contents from other page via XMLHttpRequest



"JP" <jpkeisala@gmail.com> wrote in message
news:1147536530.306022.234940@g10g2000cwb.googlegr oups.com...[color=blue]
> Hello,
>
> I am trying to figure out how can I read particular content of the page
> after I have requested page into XMLHttpRequest object.
> Is there a way to parse somehow responseText? In pseudo code I want to
> do something like this.
>
> var myHeader = myXMLHttpRequest.document.getElementById("Header") ;
>[/color]

Try putting in a hidden iframe:

<iframe id="myXMLHttpIframe" style="display:none;">
...
myXMLHttpIframe.document.body.innerHTML =
myXMLHttpRequest..responseText;
myHeader = myXMLHttpIframe.document.body.getElementById("Head er");


JP
Guest
 
Posts: n/a
#4: May 14 '06

re: Reading part of contents from other page via XMLHttpRequest


Thanks for reply.
Seems like IFRAME is the only solution. I was quite suprise that I
cannot parse outputting HTML.
It would be nice if there would be responseHTML which would be document
object of the xmlHttprequest.

Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#5: May 22 '06

re: Reading part of contents from other page via XMLHttpRequest


JP wrote:
[color=blue]
> I am trying to figure out how can I read particular content of the page
> after I have requested page into XMLHttpRequest object.
> Is there a way to parse somehow responseText? In pseudo code I want to
> do something like this.
>
> var myHeader = myXMLHttpRequest.document.getElementById("Header") ;[/color]

Provided your HTML element has an `id' attribute of type ID and
value "Header", you could do something along

var m = myXMLHttpRequest.responseText.match(
/<[^>]+\s+id\s*=(["']|\s*)Header(["'])(\s+[^>])*>/i);

However, outputting X(HT)ML as application/(xhtml+)xml and using
a parser object or responseXML instead is the sane approach.


PointedEars
--
Those who desire to give up freedom in order to gain security,
will not have, nor do they deserve, either one.
-- Benjamin Franklin
Closed Thread