简体   繁体   English

在所有请求中添加参数javascript

[英]adding a parameter in all requests javascript

We have a application developed in Struts 1.x. 我们有一个用Struts 1.x开发的应用程序。 We are not using Ajax to POST/GET data from the server. 我们没有使用Ajax从服务器发布/获取数据。

Earlier, this UI was serving data for only one customer, and now we are updating our server to provide data for all customers based on 'customer id'. 之前,该UI仅为一个客户提供数据,现在我们正在更新服务器,以基于“客户ID”为所有客户提供数据。 The 'customer id' has to be passed in all requests to server and we need to achieve this with minimal changes. 必须在所有请求中将“客户ID”传递给服务器,而我们需要以最小的更改来实现这一点。

Is there any smart way to add 'customer id' in all requests to server? 有什么聪明的方法可以在对服务器的所有请求中添加“客户ID”? We don't want to have this parameter in the session or in cookies. 我们不想在会话或cookie中使用此参数。 This customer id will be output of a request, and all subsequent requests should have this customer id. 此客户ID将作为请求的输出,所有后续请求都应具有该客户ID。

you can make a 4 columns table in database and record customer id, ip, date and exp. 您可以在数据库中创建一个4列的表格,并记录客户ID,IP,日期和经验。 date. 日期。

You can do it by custom ajax method ($.ajax method) 您可以通过自定义ajax方法($ .ajax方法)来完成此操作

(function ($) {

var _ajax = $.ajax,

A = $.ajax = function(options) {

if (A.data) {

//TODO: the appending in here, i just don't feel like

writing all of this

}

return _ajax(options);

};

};

});
// and all your ajax calls will get that data

$.get({...})

$.post({...})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM