dousong9729 2018-04-26 09:33
浏览 410
已采纳

如何通过ajax将数据数组发送到后端(php)

I need some help here guys, my issue is that the first console.log returns what has been built by the foreach, but the backend doesn't receive that same array. This foreach basically iterates over a table, looks for a certain id, makes it an index of an array, and then it fetches all the input values from the table and pushes it to that given index.

        var dateTime = [];
        $("#employeeData > tr").each(function(dateIndex, date) {
            dateTime[date.id] = [];
            $("#" + date.id + " :input").each(function(inputIndex, inputTime) {
                dateTime[date.id].push($(inputTime).val())
            });
        });
        var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');
        console.log(dateTime);
        $.post('employee',
            {
                dates: dateTime,
                _token: CSRF_TOKEN
            }, function(response) {
                console.log(response);
            }
        );
        });
    Route::post('/employee', 'EmployeesController@updateRecords');

    public function updateRecords(Request $request)
    {
        return $request->dates;
    }
    // this is a console.log of the dateTime, each date has 4 inputs 
    //associated with it
    [2017-11-02: Array(4), 2017-11-03: Array(4), 2017-11-06: Array(4), 2017- 
    11-07: Array(4), 2017-11-08: Array(4), …]

This all happens when jquery handles a click event.

  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 Win7电脑开机出现硬件设置已更改
      • ¥15 vba代出现莫须有错误,都是一个个复制下来的为啥出错呢?
      • ¥15 /etc/vsftpd/vsftp.conf配置文件加了一行utf8_filesystem=YES之后,启动vsftpd报错
      • ¥15 W5100可以收广播,但是无法发出广播
      • ¥100 PCD点云排序和分割
      • ¥15 GG-CNN抓取数据集
      • ¥15 C++类和对象,多态性,继承,虚函数虚基类
      • ¥15 使用VS2019和Dev c++按%p输出地址,结果相差很大
      • ¥30 有偿解惑TINA老报错,求解惑
      • ¥15 arduino esp8266 编译问题