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

Call 'beforeSend' function set with $.ajaxSetup when Backbone.emulateHTT... #1756

Closed
wants to merge 2 commits into from

Conversation

mlowicki
Copy link
Contributor

...P is set to true.

Previously if we set:

Backbone.emulateHTTP = true;

and 'beforeSend' on $.ajax via:

$.ajaxSetup({
  beforeSend: function (xhr) {
    xhr.setRequestHeader('X-CSRFToken', $.cookie('csrftoken'));
  }
});

Then 'beforeSend' won't be called on xhr requests.

…HTTP is set to true.

Previously if we set:

  Backbone.emulateHTTP = true;

and 'beforeSend' on $.ajax via:

  $.ajaxSetup({
    beforeSend: function (xhr) {
      xhr.setRequestHeader('X-CSRFToken', $.cookie('csrftoken'));
    }
  });

Then 'beforeSend' won't be called on xhr requests.
params.beforeSend = function(xhr) {
var beforeSend = Backbone.$.ajaxSettings.beforeSend;
params.beforeSend = function(xhr, settings) {
beforeSend && beforeSend(xhr, settings);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beforeSend && beforeSend.apply(xhr, arguments) might be more future proof...or not worth it...just a thought. That and xhr is the correct context for beforeSend (just checked).

@braddunbar
Copy link
Collaborator

@mlowicki #1757 takes this a bit further and preserves the user provided beforeSend along with adding a test.

Would you mind giving it a shot to see if it works for you?

@mlowicki
Copy link
Contributor Author

@braddunbar What if I don't pass beforeSend to delete but set it through:

$.ajaxSetup({
  beforeSend: function (xhr) {
      xhr.setRequestHeader('X-CSRFToken', $.cookie('csrftoken'));
  }
});

Also documentation of jQuery says:

"Returning false in the beforeSend function will cancel the request".

Maybe it's worth to return value of call to the preserved 'beforeSend'?

@caseywebdev
Copy link
Collaborator

Maybe it's worth to return value of call to the preserved 'beforeSend'?

Addressed at #1758

mlowicki pushed a commit to mlowicki/backbone that referenced this pull request Oct 19, 2012
@mlowicki
Copy link
Contributor Author

Issue with not calling global beforeSend addressed at #1759

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants