1

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;
}
3
  • What is the output? moreover what is the output of var_dump($_POST['imgArr']); ? That should allow you to determine a solution. Commented Oct 17, 2018 at 16:15
  • Show us how you set imgArr Commented Oct 17, 2018 at 16:16
  • Thats my whole js - pastebin.com/zVt6zRxc Commented Oct 17, 2018 at 16:20

1 Answer 1

3

Replace

$images = $_POST['imgArr'];

With

$images = $_POST['images'];

Because the index images came from here:

data: {
    images: imgArr
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.