Explorar o código

Exercise 3: catch Ajax errors when building tooltips.

Frederic G. MARAND %!s(int64=9) %!d(string=hai) anos
pai
achega
2b47a939b1
Modificáronse 1 ficheiros con 5 adicións e 1 borrados
  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);
         }
       });
     }