jQuery's ajaxSetup - I would like to add default data for GET requests only
Starting jQuery 1.5, you can handle this much more elegantly via Prefilters:
var revision = '159';$.ajaxPrefilter(function (options, originalOptions, jqXHR) { // do not send data for POST/PUT/DELETE if(originalOptions.type !== 'GET' || options.type !== 'GET') { return; } options.data = $.extend(originalOptions.data, { r: revision });});
I think what you might be able to use is beforeSend
.
var revision = '159';$.ajaxSetup({ dataType: "json", contentType: "application/x-www-form-urlencoded; charset=UTF-8", beforeSend: function(jqXHR, settings) { if(settings.type == "GET") settings.data = $.extend(settings.data, { ... }); return true; }});
BeforeSend documentation as well as your settings available
I coded this blind, so I hope it gets you going in the right direction.