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

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);
        }
    });
}
  • 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/… " – Sammu Sundar Dec 12 '18 at 7:31
  • This is not call that controller ajaxcontroller/index controller – Sammu Sundar Dec 12 '18 at 7:32
  • just use this code for base admin url : <?php echo $this->helper('Magento\Backend\Helper\Data')->getHomePageUrl(); ?> – Rohan Hapani Dec 12 '18 at 8:34
  • Then combine => my_module/ajaxcontroller/index – Rohan Hapani Dec 12 '18 at 8:35
  • 1
    Happy to help !! Happy coding :) – Rohan Hapani Dec 12 '18 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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