Skip to content

Instantly share code, notes, and snippets.

@liketaurus
Last active December 17, 2015 07:29
Show Gist options
  • Save liketaurus/c52b6b0dc574b8b46a24 to your computer and use it in GitHub Desktop.
Save liketaurus/c52b6b0dc574b8b46a24 to your computer and use it in GitHub Desktop.
How to get current temperature with jQuery and Global Weather web service
var weather = $('#weather');
var city = "Kyiv";
var country = "Ukraine";
var temp;
$.ajax({
type: "GET",
url: "http://www.webservicex.net//globalweather.asmx/GetWeather?CityName=" + city + "&CountryName=" + country + "",
dataType: "xml",
success: function (xml) {
var t= new String (new XMLSerializer().serializeToString(xml.documentElement));
var begin =t.indexOf('F (');
var end =t.indexOf('C)');
t = t.substring(begin+3,end);
weather.html(t+'°C' );
}
});
// For local testing you'll need "Allow-Control-Allow-Origin: *" Chrome extension which can be obtained via Chrome Web Store
// https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment