jQuery getJSON的对象内部的数组未填充
本文关键字:填充 数组 对象 getJSON jQuery 内部 | 更新日期: 2023-09-27 18:19:41
我在尝试使用jQuery getJSON函数时遇到了一个相当特殊的问题。
我试图通过制作这样的对象来发送我的参数:
var args = {
from: "",
to: "",
customerId: "52"
articles: ['12312', '21521']
};
然后调用getJSON函数:
$.getJSON('/Statistics/TimeGraph', args, function (response) {
//Fill graph.
});
这就是问题的开始。我在控制器上收到了请求,但未填充articles
(其他参数为)。
控制器动作:
public JsonResult TimeGraph(DateTime? from, DateTime? to, int? customerId, string[] articles)
{
return Json("", JsonRequestBehavior.AllowGet);
}
难道不能在这样的对象内部发送数组吗?还是我遗漏了什么?
您需要将传统参数设置为true,否则它将无法正常工作。
$.getJSON('/Statistics/TimeGraph', $.param(args,true), function (response) {
//Fill graph.
});
或者简单的ajax调用
$.ajax({
type: "GET",
url: "/Statistics/TimeGraph",
data: args,
success: function(response){
//Fill graph.
},
dataType: "json",
traditional: true
});