weixin_33691700 2016-03-14 06:11 采纳率: 0%
浏览 40

AJAX发布多个数组

I have 2 input fields like so

<input type="text" name="typeDetails[games]"/>
<input type="text" name="typeDetails[art]"/>

I want to submit via AJAX, but I'm unsure how to exactly send this data. I know in my controller that I can validate the typeDetails array like typeDetails.games or typeDetails.art, but I'm unsure how to send it.

Here's what my JS looks like currently.

var data = { 'typeDetails[]' : []};

$("input[name='typeDetails[games]']").each(function() {
    data['typeDetails[games]'].push($(this).val());
}); 

$("input[name='typeDetails[art]']").each(function() {
    data['typeDetails[art]'].push($(this).val());
});

The error I'm getting is "Cannot read property 'push' of undefined".

Thanks!

  • 写回答

2条回答 默认 最新

  • weixin_33691598 2016-03-14 08:27
    关注

    'typeDetails[games]' and 'typeDetails[art]' are not the keys of data.

    Declare data like this

    var data = { 'typeDetails[games]' : [],  'typeDetails[art]' : []};
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在音频中嵌入字符串(水印)信息进行传递
  • ¥30 plc怎么以设计说明书申请软著
  • ¥15 硬盘识别不了,需要初始化,可我的数据怎么办
  • ¥15 lvm2被mask了,怎么unmask都没用(标签-ubuntu|关键词-apt)
  • ¥15 交叉注意力机制的残差问题
  • ¥15 微信小程序:渲染收货地址时页面不显示
  • ¥20 win7 64位DirectShow提示初始化失败如何解决?
  • ¥20 小规模孤立词识别系统设计
  • ¥15 关于Java对接海康威视车牌识别一体机SDK是否需要固定外网的IP?
  • ¥15 Linux扩容时,格式化卡住了:vgdispaly查看卷组信息,没有输出