'The jquery ajax function is not giving any output but is throwing a 403 error

I have an ajax function in jquery caling a cakephp4 function. The function doesnt work as it is giving a 403 forbidden error. The error is about headers but i cant find what I need to fix this exactly.

This code runs and it does get the var (alert verifies this). Nothing works ? jquery ///

var freeassessmentid = "<?=$testid?>";
  
  $.ajax({
            url: "/freeassessments/freeasssesmenFinaltResult", //path is correct and it can be tested on its own
            method: "POST",
            dataType: "html",
            data: { freeassessmentid:freeassessmentid  },
            success: function(response) {
                //console.log(response);
                   
                  $('#display-area').append(response);  //no output
               }
               
               
               
            });

public function freeasssesmenFinaltResult($freeassessmentid=0)
 {
//debug('test');
 $html .= '<li class="listyle" style="height: auto;">hi<br/></li>';
          $html .= '</ul>';
//no output

 //https://stackoverflow.com/questions/36666256/jquery-ajax-call-results-in-error-status-403


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source