JavaScript AJAX Basics (retiring) jQuery and AJAX Handle AJAX failures with jQuery

Task for jQuery AJAX fail() method is refusing to evaluate my answer, but jqXHR object is being accessed. What now?

Hi everyone!

I'm stuck on the final stage of a Challenge Task on jQuery's AJAX .fail() method. The task calls for us to alert the user with the jqXHR object's statusText property. I've added the code and the alert box is popping up with the 'Not Found' status text, but Treehouse's editor is refusing to evaluate my code.

Where am I going wrong here?

Thanks for your help in advance!

George

app.js
$.get("missing.html", function(data) {
  $("#footer").html(data);
}).fail( function( jqXHR ) {
  alert( jqXHR.statusText );
});
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>

1 Answer

Yours:

$.get("missing.html", function(data) {
  $("#footer").html(data);
}).fail( function( jqXHR ) {
  alert( jqXHR.statusText );
});

One that works:

$.get("missing.html", function(data) {
  $("#footer").html(data);
}).fail(function(jqXHR) {
  alert(jqXHR.statusText)
});

What's the difference? I pasted yours into the Challenge and removed the spaces you had around the anonymous function's parameter and the alert function's parameter! Wow! The editor is a bit picky.

I tried that after getting a bit frustrated, and you're right - it did work :) I'm a bit disappointed that the editor is so fussy when it comes to the user's own syntactical styling.

Thanks for the input!