$_POST variable empty after AJAX Request
HTML
<div id="banner-message">
<p>Send Post</p>
<button>Send Post Ajax</button>
</div>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQ-bKE_oPXorefsLMe-cFJOKSSOnGLxQ-icQ8ai4umrVMOp1ddB&usqp=CAU">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcSHZpkCWtUX17YT92S9kknlCmHllPYUf7qU7p8_DwVY0rLQ-Nji&usqp=CAU">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQAQRXPpIVlUF6CluMs7IQ1ABAdk365roI8_XISN-c1VHGHu42b&usqp=CAU">
<img class="highlight" src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcS1lQqXp_ll8lmCvygRuNrfK0ctOD1TGqUDskcNNHknDL4mrwEx&usqp=CAU">
<img class="highlight" src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQY7uK3oFaEMh45nDElZXrsiyxqjd6lfEwja0nFJvnfSD6lRZyC&usqp=CAU">
JavaScript
// find elements
var button = $("button")
// handle click and add class
button.on("click", function(){
var images = document.getElementsByTagName('img');
var images2remove = [];
$(images).each(function() {
if($(this).hasClass('highlight')) {
var path = $(this).attr('src');
images2remove.push(path);
}
});
images2remove = JSON.stringify(images2remove);
$.ajax({
url: '/echo/json/',
type: 'post',
data: {'json' : images2remove},
success: function(response) {
if(response != 0) {
console.log(response);
}
else {
alert('file not removed');
}
}
});
//console.log({'images' : images2remove});
});