I wanted to add a csrf token to all request bodies for ajax requests. i found the following post useful: jQuery add CSRF token to all $.post() requests' data
$.ajaxPrefilter(function (options, originalOptions, jqXHR) {
options.data = $.param($.extend(originalOptions.data, { c: csrf }));
});
For some reason, this ovewrites the request body. i do not understand why. i can see when i serialize the request body its all there, but when it submits the body only contains the c
field. It may be helpful to note that i am creating the form data using jQuery's serialize()
method.