1

My ajax call not working . It returns

"A technical problem with the server created an error. Try again to continue what you were doing. If the problem persists, try again later."

my ajax call code

function validateAuthorize()
{
    require([
        "jquery"
    ]

, function($){

var name = $('#name').val();
var email = $('#email').val();
$.ajax({
    url: '<?php echo $block->getUrl('path/ajaxcontroller', ['_nosid' => true]); ?>',
    showLoader: true,
    data: {name:name,email:email,form_key:'<?php echo $block->getFormKey(); ?>'},
    type: "POST",
    success: function(result){
        jQuery('#message').html(result);
    }
});

}

controller

My\Module\Controller\Adminhtml\Ajaxcontroller\Index.php

<?php
    namespace My\Module\Controller\Adminhtml\Ajaxcontroller;

    class Index extends \Magento\Backend\App\Action
    {
        protected $resultPageFactory;

        public function __construct(
            \Magento\Backend\App\Action\Context $context,
            \Magento\Framework\Controller\Result\JsonFactory $resultPageFactory
        ) {
            parent::__construct($context);
            $this->resultPageFactory = $resultPageFactory;
        }

        public function execute()
        {
            if($this->getRequest()->isAjax()){
                echo "Testing";
            }
            return false;
        }
    }

Earlier ajax was working properly currently it returns

A technical problem with the server created an error. Try again to continue what you were doing. If the problem persists, try again later

12

1 Answer 1

2

Change ajax code like below way :

$.ajax({
        url: 'admin/my_module/ajaxcontroller/index',
        showLoader: true,
        data: {name:name,email:email,form_key:'<?php echo $block->getFormKey(); ?>'},
        type: "POST",
        success: function(result){
            jQuery('#message').html(result);
        }
    });
}
7
  • 1
    this is not working .I call ajax in dashboard page . in ajax call while i inspect it call below url"localhost/magento/adminpage/path/dashboard/index/key/… " Dec 12, 2018 at 7:31
  • This is not call that controller ajaxcontroller/index controller Dec 12, 2018 at 7:32
  • just use this code for base admin url : <?php echo $this->helper('Magento\Backend\Helper\Data')->getHomePageUrl(); ?> Dec 12, 2018 at 8:34
  • Then combine => my_module/ajaxcontroller/index Dec 12, 2018 at 8:35
  • 1
    Happy to help !! Happy coding :) Dec 12, 2018 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.