Reading part of contents from other page via XMLHttpRequest

J

JP

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");
 
M

Martin Honnen

JP said:
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");

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.
 
J

JP

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.
 
T

Thomas 'PointedEars' Lahn

JP said:
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");

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top