Fetch php in JavaScript (DOM)

T

tramblie

The below code is the result of an external HTTP request
www.externalsite.com/index.php?sv_path=98,110
How can I "extract" the value '1,107' (a static value, at the row 27)
in JavaScript DOM of another file such like www.mysite.com/myfile.htm
?:


<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8" />
<title>MYTITLE</title>
<link rel="stylesheet" type="text/css" href="css/
master_style.css" />

</head>

<body>

<div id="wrapper">
<div id="content">
<div id="body" class="blue">

<div class="listitem">
<div class="changes">
<div>
<div class="my_value"><strong>1,129</strong> EUR / L</
div>
<div class="my_value"><strong>270,55</strong>
myvalute / L</div>
</div>
</div>
</div>

<div class="listitem">
<div class="changes">
<div>
<div class="my_value"><strong>1,107</strong> EUR / L</
div>
<div class="my_value"><strong>265,28</strong>
myvalute / L</div>
</div>
</div>
</div>

<div class="listitem">
<div class="changes">
<div>
<div class="my_value"><strong>1,050</strong> EUR / L</
div>
<div class="my_value"><strong>251,62</strong>
myvalute / L</div>
</div>
</div>
</div>

<div class="listitem">
<div class="changes">
<div>
<div class="my_value"><strong>0,520</strong> EUR / L</
div>
<div class="my_value"><strong>124,61</strong>
myvalute / L</div>
</div>
</div>
</div>

</div>
</div>
<div class="clear">&nbsp;</div>
</div>
</body>
</html>




THANX
 
T

Thomas 'PointedEars' Lahn

tramblie said:
The below code is the result of an external HTTP request
www.externalsite.com/index.php?sv_path=98,110
404-compliant.

How can I "extract" the value '1,107' (a static value, at the row 27)
in JavaScript DOM of another file such like www.mysite.com/myfile.htm

Same here.
?:

[snip markup]

Since this appears to be an XHTML fragment, you should use the responseXML
property of the XHR object, and apply to it one of XPath, DOM 2 Traversal,
or firstChild/nextSibling traversal. I would prefer XPath. The only
question is: Are you authorized to reuse/republish that information?


PointedEars
 
T

tramblie

tramblie said:
The below code is the result of an external HTTP request
www.externalsite.com/index.php?sv_path=98,110
404-compliant.

How can I "extract" the value '1,107' (a static value, at the row 27)
in JavaScript DOM of another file such likewww.mysite.com/myfile.htm

Same here.
[snip markup]

Since this appears to be an XHTML fragment, you should use the responseXML
property of the XHR object, and apply to it one of XPath, DOM 2 Traversal,
or firstChild/nextSibling traversal.  I would prefer XPath.  The only
question is: Are you authorized to reuse/republish that information?

PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
  -- from <http://www.vortex-webdesign.com/help/hidesource.htm>

Oooops! I apologize: the link is not real, is just an example...
However, i need only the value, for daily monitoring of
price...without loading the entire page with style and other (for me)
useless informations.
Thanks again ;)
 
T

tcole6

On Jul 7, 11:23 am, Thomas 'PointedEars' Lahn <[email protected]>
wrote:
[snip]
Since this appears to be an XHTML fragment, you should use the responseXML
property of the XHR object, and apply to it one of XPath, DOM 2 Traversal,
or firstChild/nextSibling traversal.  I would prefer XPath.  The only
question is: Are you authorized to reuse/republish that information?

If the resource being accessed is from a different domain, won't it be
blocked by XHR?
I get an error stating "Access to restricted URI denied" when
attempting such a thing.
This has always been quite a limitation for me when using the XHR
object. For such things, I've always
has to pass control to some backend component (a servlet in my case)
and then have that object
make the cross-domain request for me and forward the response.
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
  -- from <http://www.vortex-webdesign.com/help/hidesource.htm>

Thanks.
 
T

Thomas 'PointedEars' Lahn

tcole6 said:
If the resource being accessed is from a different domain, won't it be
blocked by XHR?

That depends on how one defines "from a different domain".
I get an error stating "Access to restricted URI denied" when
attempting such a thing.

Works as designed.
This has always been quite a limitation for me when using the XHR
object. For such things, I've always
has to pass control to some backend component (a servlet in my case)
and then have that object
make the cross-domain request for me and forward the response.

There are ways to work around the SOP.

Please learn to quote; don't quote signatures (unless you are referring to
them). And find a better newsreader, or simply refrain from putting in
newlines when you don't know where your newsreader wraps lines automatically.

<http://jibbering.com/faq/#posting>


PointedEars
 
D

David Mark

tramblie said:
The below code is the result of an external HTTP request
www.externalsite.com/index.php?sv_path=98,110
404-compliant.

How can I "extract" the value '1,107' (a static value, at the row 27)
in JavaScript DOM of another file such likewww.mysite.com/myfile.htm

Same here.
[snip markup]

Since this appears to be an XHTML fragment

Actually, it looks like a complete and invalid HTML document (not of
much use for XHR.)

[snip]
 
T

Thomas 'PointedEars' Lahn

David said:
Actually, it looks like a complete and invalid HTML document (not of
much use for XHR.)

While it could be invalid, incomplete HTML as well, when in doubt I tend to
apply Occam's razor.


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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top