Skip to content
Browse files

All 2xx responses are treated as success

  • Loading branch information...
1 parent 2884602 commit 182bf0f37844daa4f0524bf86a7b8b22d9282e42 @sstephenson sstephenson committed
Showing with 13 additions and 1 deletion.
  1. +1 −1 src/ajax.js
  2. +12 −0 test/ajax.html
View
2 src/ajax.js
@@ -12,7 +12,7 @@
xhr.onreadystatechange = function(){
if (xhr.readyState == 4) {
- if (xhr.status == 200 || xhr.status == 0) {
+ if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 0) {
if (mime == 'application/json') {
var result, error = false;
try {
View
12 test/ajax.html
@@ -197,6 +197,18 @@
t.assertEqual(MockXHR.last, xhr);
t.assertEqual('parsererror', status);
t.assert(exception.toString().match(/JSON/));
+ },
+
+ test201ResponseIsSuccess: function(t) {
+ var successFired, errorFired;
+ $.ajax({
+ success: function() { successFired = true },
+ error: function() { errorFired = true }
+ });
+
+ MockXHR.last.ready(4, 201, 'Created');
+ t.assert(successFired);
+ t.refute(errorFired);
}
});
</script>

0 comments on commit 182bf0f

Please sign in to comment.
Something went wrong with that request. Please try again.