Skip to content
PHP Logo

How can Ajax be utilized to store the results from the ergebnisauslesen.php script in PHP variables?

To store the results from the ergebnisauslesen.php script in PHP variables using Ajax, you can make an Ajax request to the script, receive the response data, and then assign it to PHP variables using a hidden form field or session variable. This way, the data can be accessed and utilized within the PHP script.

php
// AJAX request to fetch data from ergebnisauslesen.php
$.ajax({
    url: 'ergebnisauslesen.php',
    type: 'GET',
    dataType: 'json',
    success: function(data) {
        // Assign the response data to PHP variables
        <?php
        $_SESSION['result1'] = data.result1;
        $_SESSION['result2'] = data.result2;
        ?>
    },
    error: function(xhr, status, error) {
        console.error(error);
    }
});