duan051347 2016-11-20 20:18
浏览 7

PHP不捕获在jquery提交时发送的数据

;;I have a form which allows users to dynamically add a new form input row. Each time a user creates a new row. The inputs are added as an array:

$(document).ready(function() {
  var currentItem = 1;
  $('#addnew').click(function(){
   currentItem++;
   $('#items').val(currentItem);
var strToAdd = '<tr><td>Year</td><td>:</td><td><select name="year[]"  ><option value="2012">2012</option><option value="2011">2011</option></select></td><td width="7%">Week</td><td width="3%">:</td><td width="17%"><select name="week[]" ><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option></select></td><td width="8%">&nbsp;</td><td colspan="2">&nbsp;</td></tr><tr><td>Actual</td><td>:</td><td width="17%"><input name="actual[]"  type="text" /></td><td width="7%">Max</td> <td width="3%">:</td></tr>';
   $('#data').append(strToAdd);

  });
});

Check the Fiddle

The problem I'm having is when I submit the form. I'm not able to capture any of the data through my php:

$("#upload").validate({


        submitHandler: function (form) { 

             $.ajax({
                 url: '<?php echo base_url(); ?>/ajax_upload',
                 type: 'POST',
                 data: $(form).serialize(),

                 success: function(data) {
                    if(data)
                    {

                       alert("success");
                    } else {

                       alert("error");

                    }


                 },
                error: function(data){

                   alert("error");
                 },
                 cache: false,
                 contentType: false,
                 processData: false
             });

             return false;


    }


    });

When executing this code:

var_dump($_POST['year']); or echo count($_POST['year'])

I receive the following error: Message: Undefined index: year

In my firebug under the console view. POST I see the data is being posted

year%5B%5D=2012&week%5B%5D=1&actual%5B%5D=test&year%5B%5D=2011&week%5B%5D=2&actual%5B%5D=test+2&items
=3&sub=Submit+values

but it still doesn't seem to be capturing.

Any help will be appreciated

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算
    • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
    • ¥20 有人知道这种图怎么画吗?
    • ¥15 pyqt6如何引用qrc文件加载里面的的资源
    • ¥15 安卓JNI项目使用lua上的问题