$ .ajax将[]附加到密钥 [英] $.ajax appending [ ] to the key
问题描述
我正在使用Jquery 1.9.1.在发送ajax数据时遇到问题,该数据之一在其中包含数组数据. 这是我的代码:
I am using Jquery 1.9.1. Having problem in sending ajax data which has array data in one of the key. This is my code:
var obj = {"param1": 1, "param2": 2, "param3": [1, 2]};
$.ajax({
url : url,
type: "POST",
data: obj,
success: function(){}
});
但是当我在开发人员工具的网络面板中检查标题时.它显示为:
But when I checked headers in network panel of developer tool. It is displayed as this:
"param1": 1,
"param2": 2,
**"param3[]"**: [1]
**"param3[]"**: [2]
为什么要将[]
添加到param3键?有人有什么主意吗?
Why it is adding []
to the param3 key? Anyone has any idea?
我以前用过$.ajax
,这是它第一次像这样发送.
I have used $.ajax
before, this the first time it is sending like this.
推荐答案
jQuery 1.4中添加了方括号(即[])来处理多维数组.如果要删除此选项,则应将传统选项设置为true,如下所示:
The square bracket (i.e. []) added in jquery 1.4 to handle the multiple dimension array. If you want to remove this you should set the traditional option to true, as shown below:
$.ajaxSettings({traditional: true});
以下链接详细说明. 在jQuery Form Data中带有括号的问题以json格式发送数据
Following link explain the details. issue with brackets in jQuery Form Data when sending data as json
这篇关于$ .ajax将[]附加到密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!