TIMEX
TIMEX

Reputation: 272204

How do I make this AJAX Prefilter apply only to GET requests?

$.ajaxPrefilter(function (options, originalOptions, jqXHR) {
        options.data = $.param($.extend(originalOptions.data, { browser_url: window.location.pathname }));
    });

This is my code. How can I do this only with GET requests?

Upvotes: 0

Views: 782

Answers (1)

Samuel Caillerie
Samuel Caillerie

Reputation: 8275

You can test over the options.type:

$.ajaxPrefilter(function (options, originalOptions, jqXHR) {
    if(options.type.toUpperCase() === "GET")
        options.data = $.param($.extend(originalOptions.data, { browser_url: window.location.pathname }));
});

Upvotes: 1

Related Questions