I have a problem in which I’m making an AJAX call to a controller. I also want to return data in response. But, it keeps throwing some errors. Below is my code:-

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 "execute";

$.ajax({ url : url, type : 'post', data : data, success : function(result) { console.log(result); }, error : function(err) { console.log("Error : "+JSON.stringify(err)); } })


1 Answers
Best Answer

Please have a look of below URL, that will help you to solve your problem.

URL:-  http://www.webetutorial.com/question/how-to-use-ajax-on-magento-default-adminhtml-form/

Please login or Register to submit your answer
Not the answer you are looking for? Browse other questions tagged or ask your own question.