I have an ASP.NET MVC application that uses jQuery 1.3.2.
我有一个ASP。NET MVC应用程序,使用jQuery 1.3.2。
On several of the pages there is a grid that lets you select multiple items, and then calls .load
to load the details for the item.
在一些页面上,有一个网格允许您选择多个项目,然后调用.load来加载项目的详细信息。
this.$container.load(this.url, data, function() {
// Show results
});
data
containing an Array named s
that contained the selected ids.
包含一个名为s的数组的数据,该数组包含所选的id。
s = [ "2", "1" ]
s = ["2", "1"]
Using jQuery 1.3.2, data
would be posted as
使用jQuery 1.3.2,数据将被发布为
s 2
s 1
Which was sent to
这是发送给
public ActionResult SomeAction(object[] s)
and everything worked great.
一切伟大的工作。
I tried to change the jQuery library to a more recent version (1.5.1) and now my controller doesn't receive the value of s
because jQuery is posting data
like so:
我尝试将jQuery库更改为最新版本(1.5.1),现在我的控制器没有收到s值,因为jQuery发布的数据如下:
s[] 2
s[] 1
Do I need to assign an index in order for the controller to receive the value (s[1], s[2]
)? Do I need to change the controller action's signature or the way the array is generated? Right now the javascript to generate data is simply
我是否需要为控制器分配一个索引来接收值(s[1], s[2])?我需要更改控制器动作的签名还是数组的生成方式?现在,生成数据的javascript很简单
var s = new Array();
for (var id in this._selected) {
// Some checks
s.push(id);
}
1 个解决方案
#1
2
If it worked in 1.3.2, you should be able to revert to the old behaviour by setting jQuery.ajaxSettings.traditional = true
. This is a change in jQuery 1.4, and this setting allows backwards compatibility.
如果它在1.3.2中工作,您应该能够通过设置jQuery.ajaxSettings来恢复到旧的行为。传统= true。这是jQuery 1.4中的一个更改,并且允许向后兼容。
See the manual entry for $.param
for more details.
参见手册条目$。参数为更多的细节。
Using your example data:
使用您的示例数据:
var data = {s: ["2", "1"]};
// jQuery 1.7
$.param(data); // "s%5B%5D=2&s%5B%5D=1"
jQuery.ajaxSettings.traditional = true;
$.param(data); // "s=2&s=1"
// jQuery 1.3.2
$.param(data); // "s=2&s=1"
#1
2
If it worked in 1.3.2, you should be able to revert to the old behaviour by setting jQuery.ajaxSettings.traditional = true
. This is a change in jQuery 1.4, and this setting allows backwards compatibility.
如果它在1.3.2中工作,您应该能够通过设置jQuery.ajaxSettings来恢复到旧的行为。传统= true。这是jQuery 1.4中的一个更改,并且允许向后兼容。
See the manual entry for $.param
for more details.
参见手册条目$。参数为更多的细节。
Using your example data:
使用您的示例数据:
var data = {s: ["2", "1"]};
// jQuery 1.7
$.param(data); // "s%5B%5D=2&s%5B%5D=1"
jQuery.ajaxSettings.traditional = true;
$.param(data); // "s=2&s=1"
// jQuery 1.3.2
$.param(data); // "s=2&s=1"