I want to display current weather of my city on my website using yahoo weather API and jQuery.
Here is my code.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function () {
$.ajax({
type: "GET",
url: "http://weather.yahooapis.com/forecastrss?w=12758714",
dataType: "xml",
success: function (xml) {
var title = $(xml).find('condition').attr('temp');
$('<div> </div>').html('<p>' + title + '</p>').appendTo('#a');
},
error: function (data) {
$('<div> </div>').html('<p> Error </p>').appendTo('#a');
}
});
});
</script>
</head>
<body id="a">
</body>
</html>
When I am running this code, Error is being displayed. I am new to jQuery and ajax so not able to solve this problem. When I open http://weather.yahooapis.com/forecastrss?w=12758714 to my browser and save all the content of it to an xml file, and then give the url of that xml file, my code is running perfectly. But with url, It not. Can anyone please help me with this?
Thanks you in advance