In my custom module have a custom ajax request for sending selected date (datepicker) to controller and found this exception when access controller
Block1 exception(s): Exception #0 (BadMethodCallException): Missing required argument $resultJsonFactory of Larsa\ASlider\Controller\Index\indexquote
Controller:
namespace Larsa\ASlider\Controller\Index;
class Index extends \Magento\Framework\App\Action\Action{
protected $resultJsonFactory;
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
) {
parent::__construct($context);
$this->resultJsonFactory = $resultJsonFactory;
}
public function execute()
{
$result = $this->resultJsonFactory->create();
if ($this->getRequest()->isAjax())
{
return $result->setData([
'test'=>'test'
]);
}
}}
JS:
var AjaxUrl = 'workshop/index/index';
$('#datePicker').datepicker({
onSelect: function (date) {
$.ajax({
showLoader: true,
url: AjaxUrl,
data: {
date: $("#datePicker").datepicker("getDate")
},
type: "POST",
dataType: 'json'
}).done(function (data) {
alert('success');
}).error(function () {
alert('error');
});
}
});
$('#datePicker').show();
Thanks in advance for help.