How to send the ajax jquery requst to the controller in cakephp 4.2,Below is the code that i tried but the post request is not sent to the controller

$.ajax({
type: “POST”,
url: ‘/ajax/ajaxrequest’,
data: “mobile=” + mobile + user_type_s,
success: “success”,
dataType: ‘text’,
context: document.body
})

Are there any errors in your JavaScript console? Are you sure that the request is not sent? Maybe it’s sent but to the wrong URL?

@Zuluru thanks for your reply, there were no errors in the JavaScript. Even though the request is not sent to the controller

Do you know for sure that this code is even being run? If you check your browser’s developer tools, does it show the request being attempted?

@Zuluru Thanks for your replay I tried these things but the main problem is there is no any error in console and also there is not any request occuring in the network tab.Only the beforeSend method is executing.

If there’s no request being sent, then the problem is in your JavaScript, which is not going to be Cake-specific. You’ve shown the Ajax call that you’re trying to do, but no context around what’s calling or triggering it.