Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts

    Get the number from a remote webpage

    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:
    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)

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,216
    Thanks
    75
    Thanked 4,344 Times in 4,310 Posts
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by Old Pedant View Post
    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)

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,216
    Thanks
    75
    Thanked 4,344 Times in 4,310 Posts
    ??? 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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by Old Pedant View Post
    ??? 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...

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,216
    Thanks
    75
    Thanked 4,344 Times in 4,310 Posts
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by Old Pedant View Post
    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 (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

    Code:
    function getData(){
    			var postsTodayValue = 300;
    			var postsToday = document.getElementById("postsToday");
    			postsToday.innerHTML = postsTodayValue;
    		}
    How do I get postsTodayValue to equal the value of this.


    The code for the gadget:
    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>

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,216
    Thanks
    75
    Thanked 4,344 Times in 4,310 Posts
    Well, doesn't look like a true gadget, to me, but whatever.

    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 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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Ludatha (12-07-2009)

  • #9
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by Old Pedant View Post
    Well, doesn't look like a true gadget, to me, but whatever.

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

  • #10
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,216
    Thanks
    75
    Thanked 4,344 Times in 4,310 Posts
    Just add one line, in red below:
    Code:
    <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".
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #11
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts
    Quote Originally Posted by Old Pedant View Post
    Just add one line, in red below:
    Code:
    <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:

    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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •