Skip to content

Commit

Permalink
Clean up logic in onComplete for cogency #2713
Browse files Browse the repository at this point in the history
  • Loading branch information
jlukic committed Jul 23, 2015
1 parent 7849999 commit 66c89ad
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/definitions/behaviors/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,20 @@ $.api = $.fn.api = function(parameters) {
}
settings.onSuccess.call(context, response, $module, xhr);
},
complete: function(maybeResponse, xhr) {
complete: function(firstParameter, secondParameter) {
var
// ajax deferred returns either response or xhr depending on success/fail
response = module.get.responseFromXHR(maybeResponse)
xhr,
response
;
// have to guess callback parameters based on request success
if( module.was.succesful() ) {
response = firstParameter;
xhr = secondParameter;
}
else {
xhr = firstParameter;
response = module.get.responseFromXHR(xhr);
}
module.remove.loading();
settings.onComplete.call(context, response, $module, xhr);
},
Expand Down

0 comments on commit 66c89ad

Please sign in to comment.