I have used JavaScript to turn data from a file into an array. I now want to use the input from a form to search through this array using PHP and display the results in a table. I have read through many posts that have solutions to something similar but I am unsure how to proceed.
I have updated my code using the suggestion posted by @Kevin_Kinsey
I am using ajax with POST to pass the array to PHP like this
function sendPhp(reports) {
$.ajax({
type: 'POST',
url: 'reports.php',
data: JSON.stringify(reports),
contentType: 'application/json',
dataType: 'json'
});
}
Then I am using this to receive it in PHP
<?php
$json = filter_input(INPUT_POST, "data", FILTER_SANITIZE_EMAIL);
//replace FILTER_DEFAULT with appropriate filter flags, as tight as possible
$dataObject = json_decode($json);
$dataArray = json_decode($json, true);
var_dump($json);
?>
my page is now displaying NULL in the browser and viewing the get request in the console shows no data being received.
Can someone point out my mistake please? I do not understand why the data is not being passed.
This image shows the console log my POST which shows my array
This image shows the console log of the GET on my PHP page which is empty.