[jQuery] jQuery, Yahoo Weather and IE Problems
Hello,
I'm new to list and I have searched and plugged away on this issue for
a few days and not found a definitive answer. I'm fairly new to jQuery
but I am a very well versed web developer although this one has caught
me out.
I have been working to replace an ageing website and within that the
ageing weather 'applet' that sits on the homepage
(www.worthing.gov.uk) unfortunately the old weather applet has broken
before I can replace the old site so I have had no choice but to go
live on this applet.
I am collecting Yahoo's Weather RSS feed on a Windows Server 2003
machine using a scheduled task to download the weather using 'wget'
and saving it in the root of the web server as /weather.xml.
My problem is that by default the code works in Firefox, Opera 9 and
Safari but IE 6 and 7 don't want to know. The crux of the issue seems
to be that I can pull XML tag attributes from the loaded XML file in
IE6/7 with the following code (a condensed version):
$.ajax({
type: "GET",
url: "weather.xml",
dataType: "xml",
A current copy of the RSS feed I am downloading is available from
Yahoo here: http://xml.weather.yahoo.com/forecastrss?p=UKXX0639&u=c
If I run the code on Firefox, Opera 9 or Safari I get in the dialog
box the following: Temperature 3°C (or whatever the temperature is)
whereas on IE6/7 I get: Temperature: undefined°C. :(( It seems to be
with the pull of attributes that this happens.
I have checked that IIS is set to .xml is text/xml in the MIME types
and the only solution I have found is when you set the datatype to
text, then IE will process the XML file correctly! But of course this
breaks Gecko based browsers, WebKit/KHTML and Opera 9. So I have
kludged it with this:
var isMSIE = /*@cc_on!@*/false;
var weatherDataType="xml";
if(isMSIE){weatherDataType="text";}
$.ajax({
type: "GET",
url: "weather.xml",
dataType: weatherDataType,
success: function(data) {
var $weather=$(data).find('condition')
$temp='Temperature: '+$weather.attr('temp')+'°C';
alert($temp);
}
});
This works on all browsers but I hate coding things that check browser
versions and it just doesn't seem very clean , so I can only assume I
am doing something wrong. I have followed chapter 6 of Learning jQuery
from Packt Publishing and I cannot see where the issue lies, as I have
done what they have suggested in there.
Where have I gone wrong or is this as good as it gets? I have coded my
own AJAX XmlHttpRequest wrapper but I'd prefer to use jQuery as it is
so damn good, and it just rocks!
If anyone can tell me where I have gone wrong, I would be very
grateful.
Thanks,
Vicky Lamburn