...

View Full Version : Get the number from a remote webpage



Ludatha
12-01-2009, 07:41 PM
I'm trying to make a windows sidebar gadget and I need to just display a number that my PHP script generates.

The web page is here: http://ludatha.com/processors/sidebar/

This is my simplified code:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN"
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script language="javascript" type="text/javascript">
<!--

function getData(){
var postsTodayValue = 300;
var postsToday = document.getElementById("postsToday");
postsToday.innerHTML = postsTodayValue;
}

//-->
</script>
</head>
<body onLoad="getData()">
<strong id="postsToday">0</strong> Posts Today<br />
</body>
</html>

I want to put the number that is generated by my scripts into my little application.

Thanks.

(P.S. No I am NOT using IFRAMES)

Old Pedant
12-01-2009, 10:41 PM
So what's the URL of the PHP script that generates the number??

If it's not in the same domain, that's a problem. If it is, then it's trivial.

Ludatha
12-01-2009, 11:32 PM
So what's the URL of the PHP script that generates the number??

If it's not in the same domain, that's a problem. If it is, then it's trivial.

http://ludatha.com/processors/sidebar/

The javascript is being run on the users computer as a gadget, not really in a webpage (but it's rendered using IE)

Old Pedant
12-02-2009, 12:18 AM
??? That URL just goes to a page with the number and nothing else. No JS code, no anything.

So not sure what we are supposed to do with that.

Ludatha
12-02-2009, 12:34 AM
??? That URL just goes to a page with the number and nothing else. No JS code, no anything.

So not sure what we are supposed to do with that.

I haven't got any js because I have no idea how to do I in the first place...

Old Pedant
12-02-2009, 12:40 AM
So what *is* producing that number???? You said it's from a widget in the browser, but that's clearly not true. It's just a URL that sends back text.

Now, you *could* use it, via JS code, *IF* it's on the same site as the page that will use it.

Ludatha
12-02-2009, 04:21 PM
So what *is* producing that number???? You said it's from a widget in the browser, but that's clearly not true. It's just a URL that sends back text.

Now, you *could* use it, via JS code, *IF* it's on the same site as the page that will use it.

Im sooo confused...

I am making a WINDOWS VISTA / 7 gadget, and to do anything special you must use javascript.

I want the gadget to get the value from that link (http://ludatha.com/processors/sidebar/)(which is 10) and put it into a certain location in the gadget.

The gadget currently puts 300 instead of the actually value as dummy text


function getData(){
var postsTodayValue = 300;
var postsToday = document.getElementById("postsToday");
postsToday.innerHTML = postsTodayValue;
}

How do I get postsTodayValue to equal the value of this (http://ludatha.com/processors/sidebar/).


The code for the gadget:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN"
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script language="javascript" type="text/javascript">
<!--

function getData(){
var postsTodayValue = 300;
var postsToday = document.getElementById("postsToday");
postsToday.innerHTML = postsTodayValue;
}

//-->
</script>
</head>
<body onLoad="getData()">
<strong id="postsToday">0</strong> Posts Today<br />
</body>
</html>

Old Pedant
12-02-2009, 09:45 PM
Well, doesn't look like a true gadget, to me, but whatever.



<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN"
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function getData()
{
// this should work for MSIE 7; would need more code to make it work in all browsers
var http = new ActiveXObject("Msxml2.XMLHTTP");
http.open( "GET", "http://ludatha.com/processors/sidebar/", false );
http.send( null );
var postsToday = document.getElementById("postsToday");
postsToday.innerHTML = http.responseText;
}
</script>
</head>
<body onLoad="getData()">
<strong id="postsToday">0</strong> Posts Today<br />
</body>
</html>

That's very similar to AJAX coding, but I'm doing a *synchronous* call (instead of async, as AJAX would do) on the assumption that you *KNOW* that the URL there will always exist and be fast and local. Your page will "hang" until it gets the response from that URL, but if it's a quarter of a second or so, that seems okay to me. If not, we could change to use async.

NOTE: language= is obsolete. Stop using it.
<!-- and // --> are obsolete. Have not been needed since the days of MSIE 3. Stop using them.

Ludatha
12-07-2009, 09:45 PM
Well, doesn't look like a true gadget, to me, but whatever.



<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN"
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function getData()
{
// this should work for MSIE 7; would need more code to make it work in all browsers
var http = new ActiveXObject("Msxml2.XMLHTTP");
http.open( "GET", "http://ludatha.com/processors/sidebar/", false );
http.send( null );
var postsToday = document.getElementById("postsToday");
postsToday.innerHTML = http.responseText;
}
</script>
</head>
<body onLoad="getData()">
<strong id="postsToday">0</strong> Posts Today<br />
</body>
</html>

That's very similar to AJAX coding, but I'm doing a *synchronous* call (instead of async, as AJAX would do) on the assumption that you *KNOW* that the URL there will always exist and be fast and local. Your page will "hang" until it gets the response from that URL, but if it's a quarter of a second or so, that seems okay to me. If not, we could change to use async.

NOTE: language= is obsolete. Stop using it.
<!-- and // --> are obsolete. Have not been needed since the days of MSIE 3. Stop using them.

Thank you very much it works! exactly what I wanted.

One last thing, how can I make it update itself every 10 seconds or so, I try putting in javascript to reload the page every 10 seconds but it doesn't seem to update...

Old Pedant
12-07-2009, 10:41 PM
Just add one line, in red below:

<script type="text/javascript">
function getData()
{
// this should work for MSIE 7; would need more code to make it work in all browsers
var http = new ActiveXObject("Msxml2.XMLHTTP");
http.open( "GET", "http://ludatha.com/processors/sidebar/", false );
http.send( null );
var postsToday = document.getElementById("postsToday");
postsToday.innerHTML = http.responseText;
setTimeout("getData()", 10000);
}
</script>

BUT...

But now I wonder if you shouldn't turn this into a true AJAX call, using async instead of synchronous call??? Remember, your JS will be "dead" each time the call to the server to get the new number occurs, if you use this code "as is".

Ludatha
12-08-2009, 09:35 PM
Just add one line, in red below:

<script type="text/javascript">
function getData()
{
// this should work for MSIE 7; would need more code to make it work in all browsers
var http = new ActiveXObject("Msxml2.XMLHTTP");
http.open( "GET", "http://ludatha.com/processors/sidebar/", false );
http.send( null );
var postsToday = document.getElementById("postsToday");
postsToday.innerHTML = http.responseText;
setTimeout("getData()", 10000);
}
</script>

BUT...

But now I wonder if you shouldn't turn this into a true AJAX call, using async instead of synchronous call??? Remember, your JS will be "dead" each time the call to the server to get the new number occurs, if you use this code "as is".

I added that but nothing happens, here is my full code:


<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN"
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">

function getData()
{
// this should work for MSIE 7; would need more code to make it work in all browsers
var http = new ActiveXObject("Msxml2.XMLHTTP");
http.open( "GET", "http://ludatha.com/processors/sidebar/forumPosts/", false );
http.send( null );
var postsToday = document.getElementById("postsToday");
postsToday.innerHTML = http.responseText;

// now get their log in status
var http2 = new ActiveXObject("Msxml2.XMLHTTP");
http2.open( "GET", "http://ludatha.com/processors/sidebar/loggedIn/", false );
http2.send( null );
var box = document.getElementById("box");
if(http2.responseText == "1"){

// get latest stuff
var http3 = new ActiveXObject("Msxml2.XMLHTTP");
http3.open( "GET", "http://ludatha.com/processors/sidebar/links/", false );
http3.send( null );

box.innerHTML = '<div style="text-align:center;"><strong><a href="http://ludatha.com/profile/">Profile</a></strong><br /><strong><a href="http://ludatha.com/profile/edit/settings/">Settings</a></strong></div>' + http3.responseText;
}else{
box.innerHTML = '<center>You are not logged in, please<br /><strong><a href="http://ludatha.com/user/login/">Click Here</a></strong><br />to login</center>';
}
setTimeout("getData()", 10000);
}

</script>
</head>
<body onLoad="getData()">
<g:background
id="bg"
src="bg.png"
style="position:absolute;top:0;left:0;z-index:-999;no=repeat;" />

<div id="gadget" class="gadget">
<div class="links">
<a href="http://ludatha.com">home</a><br />
<a href="http://ludatha.com/portal/">portal</a><br />
<a href="http://ludatha.com/forum/">forum</a><br />
<a href="http://ludatha.com/arcade.html">arcade</a>
</div>
<div class="forumInfo">
<strong id="postsToday">0</strong> Posts Today<br />
<a href="http://ludatha.com/forum/">Join the Discussion</a>
</div>
<div class="box" id="box">
<div style="text-align:center;">
<strong><a href="http://ludatha.com/profile/">Profile</a></strong><br />
<strong><a href="http://ludatha.com/profile/edit/settings/">Settings</a></strong>
</div>
</div>
</div>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum