PHP error log does not log when calling AJAX PHP script

Viewed 39

DESIRED BEHAVIOR: The desired behavior would be the error_log working.

SPECIFIC PROBLEM: Error logging works only in certain context (from index.php), not from AJAX redirect.

SHORTEST CODE TO REPRODUCE: ADDED.

I have a problem with PHP error log creation. The error log prints fine when i access my index.PHP which contains just error_log function to try out the error logging.

However when I'm using AJAX to forward Javascript request to .PHP page, the PHP error logging does not work.

I have this javascript function on my index.html:

ajax_request.open('POST', 'search_foodinfo.php');

On the browser dev tools it says that the POST function succeeded:

enter image description here

In the /var/log/apache2/error.log there's no new row appearing. New row appears correctly when running index.php (with some error log function on it), but not with this POST request. What could be the problem? I'm using the PHP error logging functionality to debug my software in development.

edit2: here's the javascript code and php code:

javascript: (foodinfo.html)

    <script>

        // address bar URL
        var str = document.location.href;
        
        // id from address bar
        const result = str.split('/').pop();

        var form_data = new FormData();

        form_data.append('query', result);

        var ajax_request = new XMLHttpRequest();

        ajax_request.open('POST', 'search_foodinfo.php');

        ajax_request.send(form_data);

            ajax_request.onreadystatechange = function()
            {
                
                if(ajax_request.readyState == 4 && ajax_request.status == 200)
                {
                    // TODO
                }
            } 

    </script>

PHP script (search_foodinfo.php) (does not work):

<?php error_log("ERROR LOG TEST"); ?>

ERROR_LOG function on index.php (works):

<?php error_log("ERROR LOG TEST"); ?>
0 Answers
Related