Adding a general parameter to all ajax calls made with jQuery

后端 未结 4 1097
离开以前
离开以前 2021-01-11 09:19

I\'m using AJAX to load data from the server as needed. I\'m currently working on updating the server software to the latest version. One of the things I noticed that has ch

4条回答
  •  春和景丽
    2021-01-11 09:41

    An example using ajaxPrefilter to extend posted data :

    $.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
        if (originalOptions.type === 'POST' || options.type === 'POST') {
            var modifiedData = $.extend({},originalOptions.context.options.data,{ property:"val",property_two: "val" });
            options.context.options.data = modifiedData;
            options.data = $.param(modifiedData,true);
        } 
    });
    

提交回复
热议问题