Jump to content

AJAX.Updater Not Working


Hilly_2004

Recommended Posts

Hi Guys,

 

Wondered if you could help me. Im using prototype.js to help me add a weather console to my site using Yahoo!'s weather feed.

 

Now I've created a very basic HTML page which works as expected, however when I add that page into my site it refuses to work, leaving me very puzzled indeed!

 

http://www.e-lementdesigns.com/temp-cricket/weather/

 

Heres my example page, firstly the javascript:

 

<script type="text/javascript" src="../Scripts/prototype.js"></script>
<script type="text/javascript" language="JavaScript">


function reportError2(request) {
$F('WeatherDetails') = "Error";
}

function WeatherLookup() {
	// Swap Div contents to loading...
	document.getElementById("WeatherDetails").innerHTML = "Loading..."
	// Call XML feed
	var url = 'ajax_test.php?theCityCode='+$F('theCity');
	var params = '';
	var ajax = new Ajax.Updater({success: 'WeatherDetails'},url,{method: 'get', parameters: params, onFailure: reportError2});
}

</script>

 

Secondly, the form used:

 

 

<body onLoad="WeatherLookup();">

 

<h3>Cricket Weather:<br></h3>

<form>

<select name="theCity" id="theCity" onChange="WeatherLookup(this.value);">

 

<option selected="selected" value="0" label="Select a cricket venue">Select a cricket venue</option>

<option value="UKXX1798">Aldbrough St John</option>

<option value="UKXX1798">Barningham</option>

<option value="UKXX1798">Barton</option>

<option value="UKXX0657">Catterick</option>

<option value="UKXX0817">Cliffe</option>

<option value="UKXX0817">Cockerton</option>

<option value="UKXX0817">Haughton</option>

<option value="UKXX0556">Heighington</option>

<option value="UKXX1150">King James</option>

<option value="UKXX1150">Lands</option>

<option value="UKXX0817">Raby Castle</option>

<option value="UKXX0721">Trimdon</option>

 

 

</select>

</form>

<div id="WeatherDetails">

</div>

 

</body>

</html>

 

 

Now as I say, this works fine. The page displays "Loading..." when trying to find the feed, then when found displays the weather found in ajax_test.php

 

Now, this is all well and good but I need this to work within my site. Now surely it should just be a case of inserting the javascript into the head of the page, and the form into my site, and of course making sure that all the links point to the right location.

 

I've done this yet when I try and use the form, the feed isn't brought back and "Loading..." is just displayed.

 

Here is my PHP page:

 

<?php 

if (!$_GET["theCityCode"]) {

$xml_file=file_get_contents("http://xml.weather.yahoo.com/forecastrss?p=UKXX1150&u=c");

} elseif ($_GET["theCityCode"])  {

$xml_file=file_get_contents("http://xml.weather.yahoo.com/forecastrss?p=" . $theCityCode . "&u=c");

}


//******************** GETTING THE INFORMATION ****************************
// For getting the last build date
preg_match_all("#<lastBuildDate>(.*?)</lastBuildDate>#s",$xml_file,$today);   
$today= $today[1][0];

// For getting the title

preg_match_all("#<title>Yahoo! Weather - (.*?)</title>#s",$xml_file,$title);   
$StrippedTitle = $title[1][0];

// for getting the sunrise and the sunset 
preg_match_all("/<yweather:astronomy([^\<]*)/i", $xml_file, $res0);

// res1 for getting the sunset and sunrise
preg_match_all("/([^\"]*)/i", $res0[1][0], $res1);

// res0 contains all the information/day
preg_match_all("/<yweather:forecast([^<]*)/i", $xml_file, $res);

//************************************************************************

$n=0;
$days=count($res); // count the number of forecast days in the array
while($n<$days)
{
preg_match_all("/\"([^\"]*)/i", $res[1][$n], $array);
$day[$n] =$array[1][0];
$date[$n]=$array[1][2];
$low[$n] =$array[1][4];
$high[$n]=$array[1][6];
$text[$n]=$array[1][8];
$code[$n]=$array[1][10];
$n++;
}

echo "<p class=\"ColumnBody\"><strong>" . $StrippedTitle . "</strong></p>";

for($n=0; $n<$days;$n++) // Day Forecast day 1,2,3, ...
{



echo "<p class=\"ColumnTitle\"><a href=\"#\">" .$day[$n]. "</a></p>";

echo "<div class=\"WeatherSymbol\"><img src=\"../Images/weather/".$code[$n].".png\" ></div>";

echo "<p class=\"ColumnBody\"><strong>Today </strong><br />";

echo $text[$n]."<br>"; // Partly Cloudy

echo "low °C: ".$low[$n]."<br>"; // 8

echo "high °C: ".$high[$n]."<br>"; // 19

echo "</p><br />";

}


?>

 

I realise this seems a long request, but any help whatsoever would be really appreciated.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.