ajax重写设置全局header

 1 _ajax = $.ajax;
 2 
 3 $.ajax = function (opt) {
 4     return getPati(function (pati) {
 5         var fn, _opt;
 6         fn = {
 7             beforeSend: function (request) {}
 8         };
 9         if (opt.beforeSend) {
10             fn.beforeSend = opt.beforeSend;
11         }
12         _opt = $.extend(opt, {
13             beforeSend: function (request) {
14                 request.setRequestHeader("X-Pati", pati);
15                 request.setRequestHeader("X-PageCode", $('#pageCode').val());
16                 return fn.beforeSend(request);
17             }
18         });
19         return _ajax(_opt);
20     });
21 };

 

posted @ 2025-01-15 15:29  余-先生  阅读(29)  评论(0)    收藏  举报