JavaScript AJAX Basics (retiring) AJAX and APIs Stage 4 Challenge Answer

My code is not working at all :(

$('form').submit(function (evt) { console.log('hola'); evt.preventDefault (); var $tag = $('#seacrh'); var url = ''; var data = { tag: $tag, format:"json" } console.log('hola'); console.log($tag); console.log(data); function callback (response) { console.log(data); $.each(response, function (i, photo){ photosHTML = '<li class = "grid-25 tablet-grid-50">'; photosHTML += '<a href = " ' + + '" ></a></li>'; }); $('#photos').html(photosHTML); } $.getJSON(url, data, callback); });

Nothing is running, not even the console logs are working. I think it is obvious that the problem is the event listener because if I console.log out of it, it works. But I can-t see any difference between my code and Dave's code. :(

you loading jquery?

deebird Yes I am loading Jquery :(

3 Answers

James MacDonald
James MacDonald
Pro Student 6,268 Points

Does your code actually start with the word "JavaScript"? Also, you're missing a semicolon after

var data = { tag: $tag, format: "json" }

Fixed it already, but still it doesn't solve the main problem. I can't even log anything inside the event listener $('form').submit(function (evt) {});

I don't understand why.

Upon a quick test I get your console.log when I wrap it in a doc ready

LOL. Thank you man!