I'd like to incorporate min.us galleries into something I'm making, yet I'm having trouble accessing their API.
An example of the JSON returned from a (picked at random from google) gallery:
http://min.us/api/GetItems/mvjf2eq
{"READ_ONLY_URL_FOR_GALLERY": "vjf2eq", "GALLERY_TITLE": "Hani Talaat", "ITEMS_GALLERY": ["http://i.min.us/jmwpdw.jpg", "http://i.min.us/jm0kae.jpg", "http://i.min.us/jmvLn8.jpg"]}
Both using ajax & 开发者_如何学编程getJSON I get the same error:
- webkit : Uncaught SyntaxError: Unexpected token :
- Firebug : invalid label
Here is what I've been trying:
$.getJSON(
'http://min.us/api/GetItems/mvjf2eq?callback=?',
function(data) {
console.log(data);
});
Due to the same origin policy you cannot send cross domain AJAX requests. JSONP is one way to workaround this limitation but the server must support it which doesn't seem to be the case from the url you have shown. A correctly returned JSONP response would look like this:
someCallbackName({"READ_ONLY_URL_FOR_GALLERY": "vjf2eq", "GALLERY_TITLE": "Hani Talaat", "ITEMS_GALLERY": ["http://i.min.us/jmwpdw.jpg", "http://i.min.us/jm0kae.jpg", "http://i.min.us/jmvLn8.jpg"]})
where the client has the possibility to define the callback name instead of the JSON object you are getting.
精彩评论