Passing JavaScript variable into snippet

The way you’re submitting the data (POST with an application/json content type and a JSON string data body) cannot be read by $_GET or $_POST in PHP - that’s only available in the raw body input.

For example, like this:

$raw = file_get_contents('php://input');
$input = json_decode($raw, true);

$input is then an array with keys courseId, disCode, etc. Assuming the input is properly formatted - which you should always make sure, as users can’t be trusted. :wink:

1 Like