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 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64