I’m a noob at json (know a bit of jquery)….and trying to get a tiny script to work
I want to retrieve the time at a certain lat/lng
and made up this script in bits from what I’ve read online:
$.getJSON("http://ws.geonames.org/timezoneJSON?lat=47.01&lng=10.2&callback=?",
{ 'uID': 1 },
function(data) {
$.each(data, function(i, item) {
$("<span/>").html(item.time).html(".nowtime");
});
});
Needless to say, it doesn’t work…could someone give me a hand with it and also explain what
$(“”).html(item.time).html(“.nowtime”);
means. (I don’t understand what the first is)
Here is the json source reference: http://www.geonames.org/export/web-services.html#timezone
thanks
I originally thought the problem is most likely in the same origin policy. In order to do an AJAX request to a URL, it must be in the same domain (and port) as the page containing the Javascript code.
But after George IV’s correction, I checked it out.
The
dataobject returned in the callback is the JSON-evaled object, and it is not an array. Most likely, your code should’ve read something like:The selector is probably also wrong, You might want, for example, to put the result in a div with an id of
test. The line containing the selector in that case should be changed to:What this is saying is, get the object with id
test(the hash sign (#) indicates it is an idea), and update the content with whateverdata.timeis set to.