Skip to content

Commit

Permalink
$.ajax success callbacks include a reference to the XHR object
Browse files Browse the repository at this point in the history
  • Loading branch information
sstephenson committed Dec 15, 2010
1 parent 182bf0f commit c3171e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ajax.js
Expand Up @@ -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');
}
Expand Down
23 changes: 23 additions & 0 deletions test/ajax.html
Expand Up @@ -209,6 +209,29 @@ <h1>Zepto Ajax unit tests</h1>
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>
Expand Down

0 comments on commit c3171e5

Please sign in to comment.