Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass status and XHR to success and complete handlers #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions reqwest.js
Expand Up @@ -99,20 +99,12 @@
script.type = 'text/javascript'
script.src = url
script.async = true
if (typeof script.onreadystatechange !== 'undefined') {
// need this for IE due to out-of-order onreadystatechange(), binding script
// execution to an event listener gives us control over when the script
// is executed. See http://jaubourg.net/2010/07/loading-script-as-onclick-handler-of.html
script.event = 'onclick'
script.htmlFor = script.id = '_reqwest_' + reqId
}

script.onload = script.onreadystatechange = function () {
if ((script[readyState] && script[readyState] !== 'complete' && script[readyState] !== 'loaded') || loaded) {
return false
}
script.onload = script.onreadystatechange = null
script.onclick && script.onclick()
// Call the user callback with the last value stored and clean up values and scripts.
o.success && o.success(lastValue)
lastValue = undefined
Expand Down
9 changes: 5 additions & 4 deletions src/reqwest.js
Expand Up @@ -176,7 +176,8 @@
}

function success(resp) {
var r = resp.responseText
var r = resp.responseText,
xhr = resp
if (r) {
switch (type) {
case 'json':
Expand All @@ -198,10 +199,10 @@
}
}

fn(resp)
o.success && o.success(resp)
fn(resp, xhr.status, xhr)
o.success && o.success(resp, xhr.status, xhr)

complete(resp)
complete(resp, xhr.status, xhr)
}

function error(resp, msg, t) {
Expand Down