I would like to call an action method from within my plugin via ajax but I am always getting a 404 response.
I have a controller method that matches the ajax url:
jquery
$.ajax({
'type': 'post',
'contentType': 'application/x-www-form-urlencoded; charset=UTF-8',
'cache': false,
'data': data,
'url': 'pluginHandle/checkStatus',
'dataType': 'json',
'timeout': 50000
}).done(function (response) {
// Success
}).fail(function (error) {
// Total fail.
});
MyPluginController.php
...
/**
* Checks what the current status is RIGHT. NOW.
*
* @throws HttpException
*
*/
public function actionCheckStatus()
{
$this->requireAjaxRequest();
$response = [
'status' => 'open'
];
$this->returnJson($response);
}
...
What am I doing wrong?