dqfxao2898 2018-10-17 16:13
浏览 43
已采纳

通过ajax将数组发送到php

I am sending array via ajax to PHP. How to get the array from PHP?

$('.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);
        }
    });
});

I tried with this, but its not working

$images = $_POST['imgArr'];
foreach($images as $d) {
    echo $d;
}
  • 写回答

1条回答 默认 最新

  • douyue3800 2018-10-17 16:30
    关注

    Replace

    $images = $_POST['imgArr'];
    

    With

    $images = $_POST['images'];
    

    Because the index images came from here:

    data: {
        images: imgArr
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?