I've seen a lot of posts on this issue, but many of them are at least 3 years old, and nothing seemed to resolve my issue. I'm hoping someone can help. I created an array of strings that are paths to files on a server. I want to pass that array to a PHP file to unlink the specified files. The problem is when I pass the array to the PHP file using jQuery's ajax() function, the $_POST variable is empty so I can't do anything with the data. The URL is good and the array has a length of 1 in this example. Here is my code:
jQuery
$(".remove").click(function() {
var images = document.getElementsByTagName('img');
var images2remove = [];
$(images).each(function() {
if($(this).hasClass('highlight')) {
var path = $(this).attr('src');
images2remove.push(path);
}
})
$.ajax({
url: 'removeFiles.php',
type: 'post',
data: {images : images2remove},
contentType: false,
processData: false,
success: function(response) {
if(response != 0) {
console.log(response);
}
else {
alert('file not removed');
}
}
})
});
And my php
$images = $_POST['images'];
var_dump($images); // returns array(0){}
I've also tried:
$post = file_get_contents('php://input');
var_dump($post) // returns string(15) [object, Object]
I'm not quite sure what to do with that. Based on examples I have seen I feel I should be able to access the contents of this array using the $_POST variable. What am I missing here? Thanks as always!