Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下代码
$.post( "/factory/set",{ key : value }, function(response) { }); }, "json" );
在哪里
key = "foo" value = "bar"
但是服务器总是得到“key”和“bar”,有没有办法将key设置为变量,而不是字符串?
创建一个对象:
var data = {};
然后设置属性:
data[key] = value;
然后在您的调用中使用该对象$.post():
$.post()
$.post( "/factory/set",data, function(response) { }, "json" );