How to get JavaScript function data into a PHP variable

Use jQuery to send a JavaScript variable to your PHP file:

$url="path/to/phpFile.php";

$.get($url, {name: get_name(), job: get_job()});

In your PHP code, get your variables from $_GET['name'] and $_GET['job'] like this:

<?php
    $buffer_data['name'] = $_GET['name'];
    $buffer_data['job']  = $_GET['job'];
?>

Leave a Comment