1

I'm trying to get the value from my input field and concatenate it in my API url to search Flickr.

However my searchvalue variable is undefined, and it is driving me nuts.

How can I pass on the data from the input field to make the searching work?

$(document).ready(function() {

$("#myInput").keypress(function(event) {    
    if ( event.which == 13 ) {
        var searchvalue = $(this).val();  
         apiCall();
   }

});

function apiCall(){

    $.getJSON("http://www.flickr.com/services/feeds/photos_public.gne?tags='"+searchvalue+"'&format=json&jsoncallback=?", function(data) { 

        $.each(data.items, function(index, element){
                console.log(data.items);
        });

    }

 );}

});

piedude
  • 111
  • 1
  • 10
  • `apiCall(searchvalue)` `function apiCall(searchvalue){ ... }` ? Pretty basic question... What is confusing you about this? – Taplar Mar 15 '19 at 20:51
  • I already tried that, it works for only 1 search. Then I get this from chrome: "HTTP-Based Public Key Pinning is deprecated. Chrome 69 and later will ignore HPKP response headers." – piedude Mar 15 '19 at 20:57
  • 2
    Eh, you may want to make **that** your actual question, because that sounds like an entirely different issue. – Taplar Mar 15 '19 at 20:58
  • Ok thanks. I Will look a bit more into it. – piedude Mar 15 '19 at 21:00
  • 1
    https://stackoverflow.com/questions/53184374/http-based-public-key-pinning-is-deprecated-warning-when-using-yahoo-weather-api also without an answer, is the same error message. – Taplar Mar 15 '19 at 21:01
  • 1
    https://teamtreehouse.com/community/httpbased-public-key-pinning-is-deprecated-chrome-69-and-later-will-ignore-hpkp-response-headers Off site of S.O. this appears to be related to the endpoint you are trying to hit, though their url starts with `api.flickr.com` – Taplar Mar 15 '19 at 21:02
  • Tried to use api.flickr.com and I still get the same message. Maybe there is something wrong with my code & logic? – piedude Mar 15 '19 at 21:13
  • Like what @Taplar said, add a parameter to your apicall method. Otherwise searchvalue will be out of scope. – lloyd Mar 15 '19 at 22:05
  • I solved the problem. There was actually none, I just didn't reset the HTML because the next searches was stacking at bottom. – piedude Mar 15 '19 at 23:04

0 Answers0