Skip to content

Commit

Permalink
Ajax: HTTP 304 status code should not be treated as error.
Browse files Browse the repository at this point in the history
This adds a test for issue madrobby#386.
  • Loading branch information
hardbap authored and mislav committed Apr 9, 2012
1 parent 4e2690f commit b8f4762
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
if (xhr.readyState == 4) {
clearTimeout(abortTimeout)
var result, error = false
if ((xhr.status >= 200 && xhr.status < 300) || (xhr.status == 0 && protocol == 'file:')) {
if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304 || (xhr.status == 0 && protocol == 'file:')) {
dataType = dataType || mimeToDataType(xhr.getResponseHeader('content-type'))
result = xhr.responseText

Expand Down
11 changes: 11 additions & 0 deletions test/ajax.html
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,17 @@ <h1>Zepto Ajax unit tests</h1>
t.refute(errorFired)
},

test304ResponseIsSuccess: function(t) {
var successFired, errorFired
$.ajax({
success: function() { successFired = true },
error: function() { errorFired = true }
})

MockXHR.last.ready(4, 304, 'Not Modified')
t.assert(successFired)
t.refute(errorFired)
},
testXHRParameterInSuccessCallback: function(t) {
var body, status, xhr
$.ajax({
Expand Down

0 comments on commit b8f4762

Please sign in to comment.