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
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question javascript php equivalents

    Warning: Complete javascript noob!

    Recently, PHP was disabled on our server (frustrating!!). I used PHP to provide current weather conditions to visitors - the data was echoed to the page so screen readers could actually read it (when looking at code view you saw the actual output not the script). I was wondering if there is any javascript equivalents to the following php code:

    Code:
    <?php 
    $url = 'http://www.weather.gov/xml/current_obs/KAUG.xml'; 
    $xml = simplexml_load_file($url); 
    
     
    echo '<strong>Augusta weather: </strong><br />'; 
    if ($xml->weather == "NA"){			
    	// do something with the content
    	echo "Weather conditions not available.<br />"; 				   
    	 }else {		
    	echo $xml->weather, '<br />'; 	
    	 }
    	 
    echo $xml->temperature_string, '<br />'; 
    echo $xml->relative_humidity, '% humidity <br />'; 
    ?>
    I have a javascript that displays the current weather from Super Pages but this info is not readable by a screen reader - when looking at code view, you see the script call not the actual output.

    Thanks for any info.
    Trish

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    As far as I know can't be done only with javascript without any server side scripting because you need to access a url which is not on your domain. I'm sorry.
    Change your host or hosting plan if you can.

    best regards

  • #3
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks - i was kind of expecting that but hoped for a miracle! LOL Unfortunately, this is a state government site, so no possibility of changing hosts.

    Thanks again,
    Trish

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by lunarbaby View Post
    Thanks - i was kind of expecting that but hoped for a miracle! LOL Unfortunately, this is a state government site, so no possibility of changing hosts.

    Thanks again,
    Trish
    do you have access to other server scripting languages? perl for example.

    Edit: I know is a complication but only thing you need from the wether.com is the data which is updated on each hour only. So you could consider to get the data somewhere else, on other server, and upload to this server.

    best regards
    Last edited by oesxyl; 02-09-2009 at 04:40 PM.

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,333
    Thanks
    11
    Thanked 587 Times in 568 Posts
    noaa also provides an rss feed of current observations.
    there is not as much organization as the xml file, but at least most of the data is there.


    you can find lots of server-less ways of displaying rss feeds on your site.

    many site provide javascript widgets (google comes to mind).

    yahoo pipes can be used to convert rss to jsonp, which you can use in your page from a script tag.

    let me know if you want an example cooked up.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #6
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    @oesxyl: unfortunately, perl is off limits too- thanks for the input though.

    Quote Originally Posted by rnd me View Post
    noaa also provides an rss feed of current observations.
    there is not as much organization as the xml file, but at least most of the data is there.


    you can find lots of server-less ways of displaying rss feeds on your site.

    many site provide javascript widgets (google comes to mind).

    yahoo pipes can be used to convert rss to jsonp, which you can use in your page from a script tag.

    let me know if you want an example cooked up.
    If you get a sec., I would very much appreciate an example.
    Thanks!

  • #7
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,333
    Thanks
    11
    Thanked 587 Times in 568 Posts
    Quote Originally Posted by lunarbaby View Post
    If you get a sec., I would very much appreciate an example.
    Thanks!

    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>weather example</title>
    </head>
    <body>
    
    <div id='weather'>Loading Weather...</div>	
    
    <script type='text/javascript'>
    
    function rssCB (data){
        var vv = data.value.items[0]; 
       document.getElementById("weather").innerHTML= "<b>"+vv.title+"</b><br>"+vv.description;
    }
    
    function jsGet(turl) {
    	var xJs = document.createElement("script");
    	document.getElementsByTagName("head").appendChild(xJs);
    	xJs.src = turl;
    }
    
    function updateWeather() {
    	jsGet("http://pipes.yahoo.com/pipes/pipe.run?_callback=rssCB&_id=9oyONQzA2xGOkM4FqGIyXQ&_render=json&feed=http%3A%2F%2Fwww.weather.gov%2Fxml%2Fcurrent_obs%2FK40B.rss");
    }
    
    window.onload= function (){
    	updateWeather();
    	setInterval(updateWeather, 1000 * 60 * 60); // update each hour (this can be removed)
    }
    
    </script>
    </body>
    </html>
    tested in FF3, IE7.



    you can use string methods to parse the description to reformat the info. hint: (,:"%)
    Last edited by rnd me; 02-09-2009 at 09:01 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #8
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wow, that was quick - i'm headed out of the office now but will try this tomorrow. Thanks so much.

  • #9
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmmm- this didn't seem to work. Not sure if this is why but the following error appeared in firefox firebug:
    Code:
    document.getElementsByTagName("head").appendChild is not a function
    [Break on this error] document.getElementsByTagName("head").appendChild(xJs);
    I tried it in firefox 3.06 and IE 6.....

    Thanks very much.
    Trish

  • #10
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,333
    Thanks
    11
    Thanked 587 Times in 568 Posts
    oops: i converted a function of mine into a standard call, but i left something out:
    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>weather example</title>
    </head>
    <body>
    
    <div id='weather'>Loading Weather...</div>	
    
    <script type='text/javascript'>
    
    function rssCB (data){
        var vv = data.value.items[0]; 
       document.getElementById("weather").innerHTML= "<b>"+vv.title+"</b><br>"+vv.description;
    }
    
    function jsGet(turl) {
    	var xJs = document.createElement("script");
    	document.getElementsByTagName("head")[0].appendChild(xJs);
    	xJs.src = turl;
    }
    
    function updateWeather() {
    	jsGet("http://pipes.yahoo.com/pipes/pipe.run?_callback=rssCB&_id=9oyONQzA2xGOkM4FqGIyXQ&_render=json&feed=http%3A%2F%2Fwww.weather.gov%2Fxml%2Fcurrent_obs%2FK40B.rss");
    }
    
    window.onload= function (){
    	updateWeather();
    	setInterval(updateWeather, 1000 * 60 * 60); // update each hour (this can be removed)
    }
    
    </script>
    </body>
    </html>
    what a difference a [0] makes...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #11
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can try to change of server.
    Best regard.


  •  

    Tags for this Thread

    Posting Permissions

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