Last active
December 17, 2015 07:29
-
-
Save liketaurus/c52b6b0dc574b8b46a24 to your computer and use it in GitHub Desktop.
How to get current temperature with jQuery and Global Weather web service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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