我有以下要求:

const flickrApiPoint = "https://api.flickr.com/services/feeds/photos_public.gne";

try {

  $.ajax({
    url: flickrApiPoint,
    dataType: 'jsonp',
    data: { "format": "json" },
    success: function (data) {
      console.log(data); //formatted JSON data
    }
  });
}
catch (e) {
  console.log(e);
}


但最终我得到了

Uncaught ReferenceError: jsonFlickrFeed is not defined
    at photos_public.gne?&callback=jQuery331016421245174669186_1523107884637&format=json&_=1523107884638:1


我做错了什么以及如何解决?提前致谢!

最佳答案

您的URL flickrApiPoint不完整。它必须是const flickrApiPoint = "https://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?";

完整示例:

const flickrApiPoint = "https://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?";

    try {

          $.ajax({
            url: flickrApiPoint,
            dataType: 'jsonp',
            data: {format: "json"},
            success: function (data) {
              console.log(data); //formatted JSON data
            }
      });
    }
    catch (e) {
      console.log(e);
    }

07-26 09:36