Reputation: 435
I use $.ajaxPrefilter
to add extra data (object) to every request.
$.ajaxPrefilter(function(opt, origOpt, xhr) {
//app.user is a predefined object, eg. {username:'john', role:1}
if(app.user) {
opt.data = $.extend(origOpt.data, app.user);
}
});
But the posted data seems (in Firefox network panel > Params tab) read as literal [object Object]
instead of key-value pair post data.
Thanks for help.
Upvotes: 1
Views: 1188
Reputation: 2568
Maybe, you should try .ajaxSetup()
instead?
$.ajaxSetup({
data: app.user ? app.user : {}
});
Upd.
Try to converd data
to string, as suggested here:
$.ajaxPrefilter(function(options, origOptions, jqXHR) {
if (app.user) {
options.data = $.param($.extend({}, origOptions.data, app.user));
}
});
Upvotes: 1