I have a problem in which I'm making an AJAX call to a controller. But, I am not able to check whether it is working or not. I also want to return data in response. But, it keeps throwing some errors. Below is my code:
<?php
namespace MyNameSpace\MyModule\Controller\Index;
class Custom {
protected $request;
public function __construct(\Magento\Framework\App\Request\Http $request) {
$this->request = $request;
}
public function getPost() {
return $this->request->getPost();
}
public function __execute() {
echo "success";
}
}
But I keep receiving some or the other errors, below is my AJAX call and it is working and sending proper data:
$.ajax({
url : url,
type : 'post',
data : data,
success : function(result) {
console.log(result);
},
error : function(err) {
console.log("Error : "+JSON.stringify(err));
}
})
protected $_resultPageFactory; public function __construct(Context $context, \Magento\Framework\View\Result\PageFactory $resultPageFactory) { $this->_resultPageFactory = $resultPageFactory; parent::__construct($context); } public function execute() { echo "success"; }