PHP Post doesn't receive jQuery ajax post value
I have created an ajax POST with jQuery to obtain the ID of a div and pass it to a PHP function. The function of php is in a folder phpFunction taht contains the file phpFunc.php in the same root of index.php. The post request is:
$(document).ready(function() {
            $('.openModal').click(function() {
                var divId = $(this).attr('id');
                // Invia l'ID al server tramite richiesta AJAX
                $.ajax({
                    type: 'POST',
                    url: 'http://localhost/icollegati/phpFunction/phpFunc.php',
                    data: {divId: divId},
                    success: function(response) {
                        // Gestisci la risposta del server
                        console.log("Risposta",response);
                    }
                });
            });
        });
the PHP function is:
function FetchIdNumber(){
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Verifica se il parametro "divId" è stato inviato tramite POST
    if (isset($_POST['divId'])) {
        $id = $_POST['divId'];
        echo "ID: " . $id;
        return $id;
    }
  }
};
Thanks in adavance for the help.
 
    