Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript AJAX Basics (retiring) jQuery and AJAX Add a callback

Why is Line 4 flawed?

I'm just trying to learn WHY this DOESN'T work. Thanks!

app.js
var url = "footer.html"
var callback = function (response) {
  var footer = $('#footer');
  footer.html(response);
};

$.get(url, callback);
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>AJAX with JavaScript</title>
</head>
<body>
  <div id="main">
    <h1>AJAX with jQuery</h1>
  </div>
  <div id="footer"></div>
  <script src="jquery.js"></script>
  <script src="app.js"></script>
</body>
</html>

In other words, this works but I don't see why my original code doesn't:

var url = "footer.html"
var callback = function (response) {
  $('#footer').html(response);
};

$.get(url, callback);
Steven Parker
Steven Parker
231,172 Points

I don't see a significant difference between these, I suspect the problem may be elsewhere. Can you make a snapshot of the workspace and provide the link to it?

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I'm of the opinion that this would work. But these challenges are very sensitive. In general, it's a great idea to not do anything that's not explicitly stated by the challenge. In this case, it seems like they may very literally be testing for the string $('#footer').html(response) which does not currently exist in your code as you divided it up a bit by assigning the jQuery object first to a variable and then calling the html() method on the variable. It seems like it might be looking for you to call the html() method directly on the jQuery object instead of a variable that holds a reference to the jQuery object.

Hope this helps! :sparkles:

Steven Parker
Steven Parker
231,172 Points

After seeing Jennifer's suggestion, I went to the challenge and tried it. I got this error message: " Bummer! jQuery's html() method isn't in your script. To use it, add a period to a jQuery object, like this: $('#footer').html();"

So I agree with Jennifer, there's nothing wrong with your code technically, but challenge has specific expectations about how this will be implemented. And the message tells you exactly what it's expecting to see.

You can always report this as a bug to the Support team if you like.