简体   繁体   中英

Flickr API Error, Json callback

why I have this kind of error in my code :

"Error: jsonFlickrApi is not defined"

    $.getJSON('http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=669158895706254986e97354a3c7e9a9&photoset_id=72157623477817483&extras=original_format&format=json&jsoncallback;=?',
    function(data){
        var classShown = 'class="lightbox"';
        var classHidden = 'class="lightbox hidden"';


        $.each(data.photoset.photo, function(i, rPhoto){
            var basePhotoURL = 'http://farm' + rPhoto.farm + '.static.flickr.com/'
                + rPhoto.server + '/' + rPhoto.id + '_' + rPhoto.secret;
......

there are syme issues in JSON datatype or something else, suggest me how to fix it , pls

Thanks

The end of your URL is a bit off, this:

....&jsoncallback;=?

Should be:

....&jsoncallback=?

jQuery fills in this method on it's own with a dynamically named function (your function(data) is converted to this named function or JSONP to work). Since the format's off it's not replacing this correctly and the default method is jsonFlickrApi .

If you visit the url directly (this is without the callback) you'll see it looks like this:

jsonFlickrApi({ ... })

If you do provide a callback ( like this url ), it looks like this:

myFunction({ ... })

This is what jQuery should do, but due to the malformed URL it isn't replacing the ? , fix it and it'll do that, and it'll call the proper method, instead of the default one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM