Browse Source

Exercise 3: catch Ajax errors when building tooltips.

Frederic G. MARAND 9 năm trước cách đây
mục cha
commit
2b47a939b1
1 tập tin đã thay đổi với 5 bổ sung1 xóa
  1. 5 1
      Chapter 6/06.js

+ 5 - 1
Chapter 6/06.js

@@ -9,12 +9,16 @@ $(document).ready(function () {
       var idSelector = '#' + this.id;
       $.ajax({
         type: 'GET',
-        url: 'exercises-content.html',
+        url: 'exercises-contentz.html',
         dataType: 'html',
         success: function (data) {
           var $fragment= $('<div />').append($.parseHTML(data)).find(idSelector);
           var title = $fragment.text().trim();
           $this.attr('title', title);
+        },
+        error: function (jqXHR, textStatus, errorThrown) {
+          $('#dictionary').html('Sorry, but an error occurred: ' + jqXHR.status)
+            .append(jqXHR.responseText);
         }
       });
     }