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
form_key
as a post param not in URL.