weixin_33674437 2015-04-27 11:58 采纳率: 0%
浏览 323

通过AJAX提交表单数组

I have a form which I would like to submit via Ajax, however, part of it contains an array. I am having difficulty passing this array via Ajax. An example of my Ajax is below, where I would usually pass the form entry data via how it is below after data (one: $('#one').val()) where I would have one row of this for each field.

Now I have a new set of fields, where the information needs to be passed through as an array. I have tried using serialize and formData -- var fd = new FormData("#form") -- and so far either just this array has been passed through, or nothing from the form is passed through, or just the array is not passed through.

Can anyone please point me in the right direction?

$("#form").submit(
function() {

    if (confirm('Are you sure you want to edit this?')) {

        $("#formMessages").removeClass().addClass('alert alert-info').html(
            '<img src="images/loading.gif" /> Validating....').fadeIn(500);


        $.ajax({
            url: $("#form").attr('action'),
            dataType: 'json',
            type: 'POST',
            data: {
                one: $('#one').val(),
                two: $('#two').val()
            },

            success: function(data){
                //success stuff would be here
            }
        });

    }
    return false;
});

Thanks.

  • 写回答

2条回答 默认 最新

  • Memor.の 2015-04-27 12:08
    关注

    Have you tried this:

    Written in JavaScript:

    your_array = JSON.stringify(your_array);
    

    And in PHP:

    $array = json_encode($_POST['array']);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 netty整合springboot之后自动重连失效
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击