且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在所有的ajax调用参数添加到URL?

更新时间:2021-08-20 07:09:10

您可以使用的 jQuery.ajax 的高级选项。在你的情况,你应该注册一个全球性的 prefilter 修改发送数据。当心要做到这一点只要求自己的域名,否则这可能是一个安全泄漏。

You can use the advanced options of jQuery.ajax. In your case, you should register a global prefilter to modify the sent data. Watch out to do this only on request to your own domain, otherwise that could be a security leakage.

另一种选择是创建一个简单的包装功能扩展传递的选项:

Another option would be to create a simple wrapper function that extends the options passed in:

 function myAjax(options) {
     options.url = "mydomain";
     options.data = $.extend(options.data||{}, {sessionID: 12345});
     return $.ajax(options);
 }