changing beforeSend to be more accurate according to the jquery spec#73
Closed
yairgo wants to merge 1 commit intorails:masterfrom
Closed
changing beforeSend to be more accurate according to the jquery spec#73yairgo wants to merge 1 commit intorails:masterfrom
yairgo wants to merge 1 commit intorails:masterfrom
Conversation
…t are specified by the jquery documentation. on line 44 removed the variable $this because the variable el is the same thing. changed line 52 to reflect this change. on line 58 change rails#1 return the value that the global beforeSend returns. according to the jquery spec if this returns false the ajax request is aborted but that was not currently happening change rails#2 call the global beforeSend call with the context of the current beforeSend method to keep it consistent. pass in the settings param to keep consistent with jquery spec. also pass in the element which may not be necessary for all scenarios but has proven very necessary in our environment.
Member
|
Hello, thanks for the pull request. However, this has been fixed in a somewhat cleaner manner in 0ff66c4 |
This pull request was closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We are working on a part of our website and we needed to tie into the jquery global beforeSend function. While trying to use this method we were trying to cancel the ajax request in certain scenarios.
If you put in
$('a').live('ajax:beforeSend', function(event, xhr) {
return false;
});
Then the ajax request is not sent. With this change I also noticed that on line 44$this was being assigned to $ (this), but the variable el is already assigned to the equivalent of $(this), so I removed that variable.
I've also changed the jquery global beforeSend call back to be called with the same parameters that are used if you call before send without the beforeSend in rails.js
return beforeSendGlobalCallback.call(this, xhr, settings, el);
The first argument(this) ensures that the global beforeSend is called within the same context as it would have been called in if the beforeSend is not in the rails.js file. The second argument was already being passed along. The third argument is specified in the jquery docs as settings, just passing that along as is.
And last but not least, I'm passing the element that made the ajax call as the 4th argument.
This commit is just making the beforeSend method conform to the way the global beforeSend works, except for passing the element as the forth argument. I didn't see any tests around what arguments are passed to the beforeSend method but I did add a test to confirm returning false from the global beforeSend works as expected.
I would also like to make it so that the complete(and possibly error) callback will call the global callback, but I didn't want to make too many changes per pull request.
What do you guys think about this pull request? Would you be willing to accept a pull request allowing complete and or error to call the global callback as well?