Permalink
Browse files

$.ajax success callbacks include a reference to the XHR object

  • Loading branch information...
1 parent 182bf0f commit c3171e590b51b622c7c1dc7e7abe12f54e433ad9 @sstephenson sstephenson committed Dec 15, 2010
Showing with 25 additions and 2 deletions.
  1. +2 −2 src/ajax.js
  2. +23 −0 test/ajax.html
View
@@ -21,8 +21,8 @@
error = e;
}
if (error) errback(xhr, 'parsererror', error);
- else callback(result);
- } else callback(xhr.responseText);
+ else callback(result, 'success', xhr);
+ } else callback(xhr.responseText, 'success', xhr);
} else {
errback(xhr, 'error');
}
View
@@ -209,6 +209,29 @@
MockXHR.last.ready(4, 201, 'Created');
t.assert(successFired);
t.refute(errorFired);
+ },
+
+ testXHRParameterInSuccessCallback: function(t) {
+ var body, status, xhr;
+ $.ajax({
+ success: function(b, s, x) { body = b, status = s, xhr = x }
+ });
+
+ MockXHR.last.ready(4, 200, 'Hello');
+ t.assertEqual('Hello', body);
+ t.assertEqual('success', status);
+ t.assertEqual(MockXHR.last, xhr);
+
+ body = status = xhr = null;
+ $.ajax({
+ dataType: 'json',
+ success: function(b, s, x) { body = b, status = s, xhr = x }
+ });
+
+ MockXHR.last.ready(4, 200, '{"message":"Hello"}');
+ t.assertEqual('Hello', body.message);
+ t.assertEqual('success', status);
+ t.assertEqual(MockXHR.last, xhr);
}
});
</script>

0 comments on commit c3171e5

Please sign in to comment.