Consuming an API field

Code:
 $.ajax({
            url:  'https://api.flickr.com/services/feeds/photos_public.gne?tags=potato&tagmode=all&format=json&nojsoncallback=1',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            type: 'GET',
            success:function (response, textStatus, jqXHR) {                
                alert(response.title)
            },
            error: function (jqXHR, textStatus, errorThrown) {

            }
        });
Something like that. But you may have issues with access-control-allow-origin headers.
 
Last edited:
Hmm doesnt seem to work I am getting an error - I have solved the CORS issue so thats not a problem.

What I don't understand it why the web page does not look like a normal JSON page
 
SyntaxError: Unexpected token '
at Object.parse (native)

I was getting a response fine with the previous but for some reason it doesnt like the jsoncallback=1..
 
Code:
this.getPhoto = function(){
    console.log('gettinghere')
    $http
    .get('https://api.flickr.com/services/feeds/photos_public.gne?tags=potato&tagmode=all&format=json&nojsoncallback=1')
    .then(function(response){
      var photoData = response.data
      console.log(photoData)
      self.addPhoto(photoData)
    })
    // self.newPhoto = '';
  }

  self.addPhoto = function(photoData){

    var newPhotoObject = {
      title: photoData['title']
    }
    // console.log(newPhotoObject)
    self.photos.push(newPhotoObject);
    var newPho = new Photo(newPhotoObject);
    newPho.$save(function(){
      newPhotoObject = {}
    });
  }
 
I get the following error when running your js fiddle:

Uncaught Error: [$injector:modulerr] Failed to instantiate module flickrApp due to:
Error: [$injector:nomod] Module 'flickrApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
 
Back
Top Bottom