Ver Fonte

Listing 6.17: handling errors as $.get().fail().

Frederic G. MARAND há 9 anos atrás
pai
commit
8b7215579a
1 ficheiros alterados com 7 adições e 1 exclusões
  1. 7 1
      Chapter 6/06.js

+ 7 - 1
Chapter 6/06.js

@@ -76,7 +76,13 @@ $(document).ready(function () {
   $('#letter-e a').click(function (event) {
     event.preventDefault();
     var requestData = { term: $(this).text() };
-    $('#dictionary').load('e.php', requestData);
+    $.get('z.php', requestData, function (data) {
+      $('#dictionary').html(data);
+    }).fail(function (jqXHR) {
+      $('#dictionary')
+        .html('Sorry, but an error occurred: ' + jqXHR.status)
+        .append(jqXHR.responseText);
+    });
   });
 
   $('#letter-f form').submit(function (event) {