Cakephp 4 Ajax call

59 views Asked by At

In cakephp 4 and in this ajax function the the beforeSend's alert message has been displayed in the browser but the request is not sent to the server.Both success and error are not working.

Finally this ajax function is not at all working.There is no any error in console or there is no any request sent in the network tab of the browser but beforeSend is working.

What may be the problem ? Its been couple of months when we got this error but not able to figure out whats the problem is , please let me know if any one has the solution.

$.ajax({
  url: "kalyan/ajaxRequest",
  type: "POST",
  data: postcontent,
  processData: false,
  contentType: false,
  beforeSend: function (xhr) {
    // Set the CSRF token in the request headers
    xhr.setRequestHeader("X-CSRF-Token", csrfToken);
    alert("CSRF Token: " + csrfToken);
  },
  success: function (response, textStatus, jqXHR) {
    alert("Yay!");
    document.getElementById("result").innerHTML = response;
    alert(response);
  },
  error: function (jqXHR, textStatus, errorThrown) {
    alert(textStatus, errorThrown);
    console.error("Error:", errorThrown);
  },
});

I was expecting any error or success message to be shown in the console but nothing has been.

0

There are 0 answers