...

View Full Version : javascript php equivalents



lunarbaby
02-09-2009, 04:03 PM
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:



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

oesxyl
02-09-2009, 04:51 PM
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

lunarbaby
02-09-2009, 05:27 PM
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

oesxyl
02-09-2009, 05:35 PM
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.

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

rnd me
02-09-2009, 09:12 PM
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.

lunarbaby
02-09-2009, 09:38 PM
@oesxyl: unfortunately, perl is off limits too- thanks for the input though.


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!

rnd me
02-09-2009, 09:55 PM
If you get a sec., I would very much appreciate an example. :)
Thanks!




<!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: (,:"%)

lunarbaby
02-09-2009, 10:29 PM
Wow, that was quick - i'm headed out of the office now but will try this tomorrow. Thanks so much. :)

lunarbaby
02-11-2009, 07:57 PM
hmmm- this didn't seem to work. Not sure if this is why but the following error appeared in firefox firebug:


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

rnd me
02-11-2009, 11:50 PM
oops: i converted a function of mine into a standard call, but i left something out:


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

frankiben123
02-12-2009, 02:55 AM
You can try to change of server.
Best regard.
Naruto shippuden episodes (http://narutovostfr.com/naruto-shippuden-episodes)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum