Hello i’ve been working to get som json to work.
I’ve written this little piece of code:
$.getJSON("/calendar/event/test", function(data) {
$.each(data, function(i,item){
$('#test').append('<li>' + item.title + '</li>');
});
});
This works perfectly and appends the titles returned from the JSON object…
What doesn’t work is when I want a webapp to retrieve the data. This webapp is located on another domain.
I tried to change the above JSON code into a simple JSONP piece of code by doing this:
$.getJSON("http://domainname.com/calendar/event/test?callback=?", function(data) {
$.each(data, function(i,item){
$('#test').append('<li>' + item.title + '</li>');
});
});
But this doesn’t work. I get this error code: parsererror – Error: jQuery1710762373415816335_1330535356545 was not called… However, if I try to retrieve some data through JSONP from e.g. Wikipedia – this works. So maybe it’s a server setting or something similar?
I can’t figure this out, and any help in any direction is gladly appreciated!
Thanks in advance!
Your server needs to return proper JSONP. JSON is not the same thing as JSONP, JSONP has an added layer in that it is wrapped in a callback named after the GET parameter that was passed containing a callback name. For example, this would be valid JSONP: