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 trialMatthew Clark
7,255 PointsMy code is incorrect here? Help!
What is the issue with my code here?
$.get("missing.html", function(data) {
$("#footer").html(data);
}).fail(function (jqXHR){
$('#footer').statusText(errorMessage);
});
1 Answer
Ken Alger
Treehouse TeacherMatthew;
You are close, but let's take a look at this...
Task 3 of this code challenge is:
When the AJAX response fails, we should alert the user. Pop up an alert box with the XHR object's statusText property.
Using the 4 P's of problem solving (Preparation, Plan, Perform, Perfect), and we'll probably at most use three here, let's examine this problem.
Preparation
As we have gotten through the first two tasks we should be starting our Task 3 with code similar to:
$.get("missing.html", function(data) {
$("#footer").html(data);
}).fail(function(jqXHR){});
Plan
The challenge asks us to
- Pop up an alert box. Great! There is an
alert()
method for that. - ... with the XHR object's statusText property. Since our XHR object is named jqXHR, we need to use
jqXHR.statusText
.
Perform
So, using the info we have, our code will look like:
// Course: AJAX Basics
// Module: jQuery & AJAX
// Challenge: Handle AJAX failures with jQuery
// Task: 3 of 3
$.get("missing.html", function(data) {
$("#footer").html(data);
}).fail(function(jqXHR){
alert(jqXHR.statusText);
});
That not only does what the challenge asks and is direct to-the-point code, it also passes the challenge! Cool. What's next?
Happy coding,
Ken
San Francisco
28,373 PointsBless you for providing clear, concise, workable solutions for these problems. If only all answers were like this lol.
Ken Alger
Treehouse TeacherKen Alger
Treehouse TeacherEdited for markdown.