Skip to content

Commit

Permalink
bugfix Open XHR before setting xhr fields madrobby#935
Browse files Browse the repository at this point in the history
  • Loading branch information
Michal Scienski committed Aug 3, 2015
1 parent 3a0499b commit d4ddb34
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,19 @@
}
}

if (ajaxBeforeSend(xhr, settings) === false) {
xhr.abort()
ajaxError(null, 'abort', xhr, settings, deferred)
return xhr
var xhrCopy = $.extend({}, xhr)

if (ajaxBeforeSend(xhrCopy, settings) === false) {
xhrCopy.abort()
ajaxError(null, 'abort', xhrCopy, settings, deferred)
return xhrCopy
}

var async = 'async' in settings ? settings.async : true
xhr.open(settings.type, settings.url, async, settings.username, settings.password)

if (settings.xhrFields) for (name in settings.xhrFields) xhr[name] = settings.xhrFields[name]
for (name in xhrCopy) if (settings.xhr[name]) xhr[name] = xhrCopy[name]

for (name in headers) nativeSetHeader.apply(xhr, headers[name])

Expand Down
5 changes: 4 additions & 1 deletion test/ajax.html
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,10 @@ <h1>Zepto Ajax unit tests</h1>
}
})

t.assertEqual(MockXHR.last, xhr)
for (name in xhr) {
t.assertIn(name, MockXHR.last)
t.assertEqual(xhr[name], MockXHR.last[name])
}
t.assertEqual('GET', settings.type)
},

Expand Down

0 comments on commit d4ddb34

Please sign in to comment.