1
$.post('/js/register', data, function(){

});

$.get('/js/home', data, function(){
    //render the template here
});

I use these in my Backbone app. It fetches the data from the server, then renders the template.

I want to override these on a global level so that when I make these calls, "data" has the current window.location (the url) as an attribute.

For EVERY ajax call, I want to append the current url that the user is currently on.

PS - I'm using Backbone push state - does that make a difference?

TIMEX
  • 259,804
  • 351
  • 777
  • 1,080

1 Answers1

3

I think this answer should help you out https://stackoverflow.com/a/6998085/1846192

In your case:

$.ajaxPrefilter(function (options, originalOptions, jqXHR) {
  options.data = $.param($.extend(originalOptions.data, { url: window.location.href }));
});
Community
  • 1
  • 1
Mathijs Flietstra
  • 12,900
  • 3
  • 38
  • 67