Using JSONP API from forecast.io with WinJS
First off, apologies if this is a silly question, I'm new to WinJS and
relatively new to Javascript, but I've been going great til I hit this
roadblock.
I'm currently working on a weather app for Windows 8 using WinJS, and I'm
trying to pull the data from the forecast.io API, which in my case is
provided in JSONP format. I easily got it working in-browser using jQuery
and .getJSON, but since I have to use WinJS.xhr to request the data
instead I'm having some difficulty.
I can pull the data just fine using the following code:
function getWeather() {
WinJS.xhr({
type: "GET",
url: "https://api.forecast.io/forecast/*ommited API
key*/-36.044394,146.953718?callback=?&units=si",
headers: { "Content-type": "application/json" }
}).then(function complete(data) {
var weatherData = data.responseText;
(new Windows.UI.Popups.MessageDialog(weatherData,
"Success!")).showAsync().done();
}, function error(data) {
(new Windows.UI.Popups.MessageDialog("Failed.",
"Error")).showAsync().done();
});
}
This shows me the data in a popup window, so I'm sure that I've accessed
it. The problem is, I can't do anything with it. In jQuery I simply used
"data.currently.temperature" to get the current temperature data, but I
can't get something similar working in this situation.
Any help or pointers would be greatly appreciated!
P.S sorry if I butchered any terminology, I'm doing my best.
No comments:
Post a Comment