通过ajax发送数组到PHP

时间:2018-10-17 16:13:02

标签: php arrays ajax

我正在通过ajax将数组发送到PHP。如何从PHP获取数组?

$('#ownerslist').DataTable({
                "columnDefs": [
                    { "targets": [1, 2, 3, 5, 7, 8, 9, 10, 11, 12, 13], "searchable": false },
                    { "visible": false, "targets": groupColumn }
                ],

                "paging": true,
                "lengthChange": true,
                //"searching": true,
                "ordering": false,
                "info": true,
                "autoWidth": true,
                "drawCallback": function (settings) {
                    var api = this.api();
                    var rows = api.rows({ page: 'current' }).nodes();
                    var last = null;

                    api.column(groupColumn, { page: 'current' }).data().each(function (group, i) {
                        if (last !== group) {
                            $(rows).eq(i).before(
                                '<tr class="group"><td colspan="16">' + group + '</td></tr>'
                            );

                            last = group;
                        }
                    });
                }

            });

我尝试了这个,但是没有用

$('.send-image').on('click', function() {
    $.ajax({
        type:"POST",
        url:"sendimages.php",
        data: {
            images: imgArr
        },
        success: function(data) {
            console.log(data);
        },
        error: function(e) {
            console.log(e);
        }
    });
});

1 个答案:

答案 0 :(得分:3)

替换

$images = $_POST['imgArr'];

使用

$images = $_POST['images'];

因为索引images来自此处:

data: {
    images: imgArr
}