How to create AJAX action for POST requests in Magento 2.3?How to call a model method from controller in Magento2I created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Magento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom moduleCalling another controller and getting a responseMagentoFrameworkObjectManagerObjectManager givenMagento 2 : Overriding Default Contact Controller POST ActionI have created an extension to show Customer Company Name in Order grid. But when creating new order, order is not showing in order gridMagento 2 Create dynamic array From different Model Collection to use in multi select in gridMagento 2.3 Can't view module's front end page output?Magento 2.3 - Get child categories of parent
What is the word?
TV show starring two men who develop various gadgets
Does knowing the surface area of all faces uniquely determine a tetrahedron?
I have found ports on my Samsung smart tv running a display service. What can I do with it?
Using roof rails to set up hammock
Print the new site header
Would a 7805 5v regulator drain a 9v battery?
Are there examples of rowers who also fought?
How to avoid offending original culture when making conculture inspired from original
Derivation of CDF of a function that results in an exponential distribution
Right indicator flash-frequency has increased and rear-right bulb is out
Why was New Asgard established at this place?
Definition of 'vrit'
Does cooling a potato change the nature of its carbohydrates?
How is linear momentum conserved in circular motion?
Why swap space doesn't get filesystem check at boot time?
What is this plant I saw for sale at a Romanian farmer's market?
I'm yearning in grey
Regex version of strip() - Ch. 7 Automate the Boring Stuff
How to make a villain when your PCs are villains?
How did the European Union reach the figure of 3% as a maximum allowed deficit?
What does this Swiss black on yellow rectangular traffic sign with a symbol looking like a dart mean?
What is the context for Napoleon's quote "[the Austrians] did not know the value of five minutes"?
My student in one course asks for paid tutoring in another course. Appropriate?
How to create AJAX action for POST requests in Magento 2.3?
How to call a model method from controller in Magento2I created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Magento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom moduleCalling another controller and getting a responseMagentoFrameworkObjectManagerObjectManager givenMagento 2 : Overriding Default Contact Controller POST ActionI have created an extension to show Customer Company Name in Order grid. But when creating new order, order is not showing in order gridMagento 2 Create dynamic array From different Model Collection to use in multi select in gridMagento 2.3 Can't view module's front end page output?Magento 2.3 - Get child categories of parent
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
How to create a controller action that can be requested by POST properly in own custom payment module in Magento 2.3? How to create a parent class that will be extended by classes corresponding to controller actions which can be requested by POST properly in this version of Magento? I have created such a parent class:
<?php
namespace BillonPaymentController;
/**
* Ajax source
*/
class AjaxAction extends MagentoFrameworkAppActionAction
public function __construct(MagentoFrameworkAppActionContext $context)
return parent::__construct($context);
public function execute()
//(...)
The classes of the controller actions looks like this:
<?php
namespace BillonPaymentControllerMultishipping;
/**
* Ajax source that initiate payment in multishipping checkout
*/
class Initiation extends BillonPaymentControllerAjaxAction
/**
* Initiates the payment in multishipping checkout
*/
public function execute()
parent::execute();
//(...)
Such actions can be request in Magento 2.0 - 2.2 by POST (above action by '(store address)/billon/multishipping/initiation'). However I can send only GET request properly to my controller actions in Magento 2.3. After I send POST request to my action, the action redirects to the referrer with HTTP code 302. I found a ugly solution in the parent class:
<?php
namespace BillonPaymentController;
/**
* Ajax source
*/
class AjaxAction extends MagentoFrameworkAppActionAction
public function __construct()
$this->execute();
die();
public function execute()
//(...)
This solution disables the translation with a function '__'. How to resolve this problem? How to disable the redirection of POST requests from the controller actions to the referrers in Magento 2.3 in proper way? How should I change my action classes to receive POST request? Could you help me?
magento2 controllers ajax magento2.3 routing
add a comment |
How to create a controller action that can be requested by POST properly in own custom payment module in Magento 2.3? How to create a parent class that will be extended by classes corresponding to controller actions which can be requested by POST properly in this version of Magento? I have created such a parent class:
<?php
namespace BillonPaymentController;
/**
* Ajax source
*/
class AjaxAction extends MagentoFrameworkAppActionAction
public function __construct(MagentoFrameworkAppActionContext $context)
return parent::__construct($context);
public function execute()
//(...)
The classes of the controller actions looks like this:
<?php
namespace BillonPaymentControllerMultishipping;
/**
* Ajax source that initiate payment in multishipping checkout
*/
class Initiation extends BillonPaymentControllerAjaxAction
/**
* Initiates the payment in multishipping checkout
*/
public function execute()
parent::execute();
//(...)
Such actions can be request in Magento 2.0 - 2.2 by POST (above action by '(store address)/billon/multishipping/initiation'). However I can send only GET request properly to my controller actions in Magento 2.3. After I send POST request to my action, the action redirects to the referrer with HTTP code 302. I found a ugly solution in the parent class:
<?php
namespace BillonPaymentController;
/**
* Ajax source
*/
class AjaxAction extends MagentoFrameworkAppActionAction
public function __construct()
$this->execute();
die();
public function execute()
//(...)
This solution disables the translation with a function '__'. How to resolve this problem? How to disable the redirection of POST requests from the controller actions to the referrers in Magento 2.3 in proper way? How should I change my action classes to receive POST request? Could you help me?
magento2 controllers ajax magento2.3 routing
add a comment |
How to create a controller action that can be requested by POST properly in own custom payment module in Magento 2.3? How to create a parent class that will be extended by classes corresponding to controller actions which can be requested by POST properly in this version of Magento? I have created such a parent class:
<?php
namespace BillonPaymentController;
/**
* Ajax source
*/
class AjaxAction extends MagentoFrameworkAppActionAction
public function __construct(MagentoFrameworkAppActionContext $context)
return parent::__construct($context);
public function execute()
//(...)
The classes of the controller actions looks like this:
<?php
namespace BillonPaymentControllerMultishipping;
/**
* Ajax source that initiate payment in multishipping checkout
*/
class Initiation extends BillonPaymentControllerAjaxAction
/**
* Initiates the payment in multishipping checkout
*/
public function execute()
parent::execute();
//(...)
Such actions can be request in Magento 2.0 - 2.2 by POST (above action by '(store address)/billon/multishipping/initiation'). However I can send only GET request properly to my controller actions in Magento 2.3. After I send POST request to my action, the action redirects to the referrer with HTTP code 302. I found a ugly solution in the parent class:
<?php
namespace BillonPaymentController;
/**
* Ajax source
*/
class AjaxAction extends MagentoFrameworkAppActionAction
public function __construct()
$this->execute();
die();
public function execute()
//(...)
This solution disables the translation with a function '__'. How to resolve this problem? How to disable the redirection of POST requests from the controller actions to the referrers in Magento 2.3 in proper way? How should I change my action classes to receive POST request? Could you help me?
magento2 controllers ajax magento2.3 routing
How to create a controller action that can be requested by POST properly in own custom payment module in Magento 2.3? How to create a parent class that will be extended by classes corresponding to controller actions which can be requested by POST properly in this version of Magento? I have created such a parent class:
<?php
namespace BillonPaymentController;
/**
* Ajax source
*/
class AjaxAction extends MagentoFrameworkAppActionAction
public function __construct(MagentoFrameworkAppActionContext $context)
return parent::__construct($context);
public function execute()
//(...)
The classes of the controller actions looks like this:
<?php
namespace BillonPaymentControllerMultishipping;
/**
* Ajax source that initiate payment in multishipping checkout
*/
class Initiation extends BillonPaymentControllerAjaxAction
/**
* Initiates the payment in multishipping checkout
*/
public function execute()
parent::execute();
//(...)
Such actions can be request in Magento 2.0 - 2.2 by POST (above action by '(store address)/billon/multishipping/initiation'). However I can send only GET request properly to my controller actions in Magento 2.3. After I send POST request to my action, the action redirects to the referrer with HTTP code 302. I found a ugly solution in the parent class:
<?php
namespace BillonPaymentController;
/**
* Ajax source
*/
class AjaxAction extends MagentoFrameworkAppActionAction
public function __construct()
$this->execute();
die();
public function execute()
//(...)
This solution disables the translation with a function '__'. How to resolve this problem? How to disable the redirection of POST requests from the controller actions to the referrers in Magento 2.3 in proper way? How should I change my action classes to receive POST request? Could you help me?
magento2 controllers ajax magento2.3 routing
magento2 controllers ajax magento2.3 routing
asked Jan 9 at 12:41
Kamil SzmitKamil Szmit
32
32
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
To create AJAX action for POST requests in Magento 2.3, Please see the code below.
namespace BillonPaymentControllerMultishipping;
class Initiation extends MagentoFrameworkAppActionAction
protected $resultPageFactory;
protected $jsonHelper;
/**
* Constructor
*
* @param MagentoFrameworkAppActionContext $context
* @param MagentoFrameworkJsonHelperData $jsonHelper
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoFrameworkJsonHelperData $jsonHelper
)
$this->resultPageFactory = $resultPageFactory;
$this->jsonHelper = $jsonHelper;
parent::__construct($context);
/**
* Execute view action
*
* @return MagentoFrameworkControllerResultInterface
*/
public function execute()
try
return $this->jsonResponse('your response');
catch (MagentoFrameworkExceptionLocalizedException $e)
return $this->jsonResponse($e->getMessage());
catch (Exception $e)
$this->logger->critical($e);
return $this->jsonResponse($e->getMessage());
/**
* Create json response
*
* @return MagentoFrameworkControllerResultInterface
*/
public function jsonResponse($response = '')
return $this->getResponse()->representJson(
$this->jsonHelper->jsonEncode($response)
);
The problem is that the method „execute” of parent class, which extends 'MagentoFrameworkAppActionAction', is not run. How to resolve this problem? How to do that the action not be redirected to the referrer and the 'execute' method are called during the POST action request?
– Kamil Szmit
Jan 9 at 14:15
add a comment |
In Magento 2.3, controllers must implement MagentoFrameworkAppActionHttpPostActionInterface to be able to handle POST requests - https://devdocs.magento.com/guides/v2.3/extension-dev-guide/routing.html
Adding 'implements MagentoFrameworkAppActionHttpPostActionInterface' to the parent class, which extends 'MagentoFrameworkAppActionAction', and to child class, which corresponds to the controller action, change nothing. What should I change additionally?
– Kamil Szmit
Jan 9 at 15:01
add a comment |
For future reference,
I was only able to make my request work by doing the following steps in Magento 2.3.1 otherwise I was getting a 404. I checked class vendor/magento/module-authorizenet/Controller/Directpost/Payment/BackendResponse.php
for reference.
- Add the following interfaces
CsrfAwareActionInterface, (especially important because all post requests are using by default CSRF validation)
HttpGetActionInterface,
HttpPostActionInterface
- Implement the CSRF handling functions
public function validateForCsrf(RequestInterface $request): ?bool
return true;
public function createCsrfValidationException(
RequestInterface $request
): ?InvalidRequestException
return null;
- Execute
php bin/magento setup:upgrade
php cache:flush
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f257261%2fhow-to-create-ajax-action-for-post-requests-in-magento-2-3%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
To create AJAX action for POST requests in Magento 2.3, Please see the code below.
namespace BillonPaymentControllerMultishipping;
class Initiation extends MagentoFrameworkAppActionAction
protected $resultPageFactory;
protected $jsonHelper;
/**
* Constructor
*
* @param MagentoFrameworkAppActionContext $context
* @param MagentoFrameworkJsonHelperData $jsonHelper
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoFrameworkJsonHelperData $jsonHelper
)
$this->resultPageFactory = $resultPageFactory;
$this->jsonHelper = $jsonHelper;
parent::__construct($context);
/**
* Execute view action
*
* @return MagentoFrameworkControllerResultInterface
*/
public function execute()
try
return $this->jsonResponse('your response');
catch (MagentoFrameworkExceptionLocalizedException $e)
return $this->jsonResponse($e->getMessage());
catch (Exception $e)
$this->logger->critical($e);
return $this->jsonResponse($e->getMessage());
/**
* Create json response
*
* @return MagentoFrameworkControllerResultInterface
*/
public function jsonResponse($response = '')
return $this->getResponse()->representJson(
$this->jsonHelper->jsonEncode($response)
);
The problem is that the method „execute” of parent class, which extends 'MagentoFrameworkAppActionAction', is not run. How to resolve this problem? How to do that the action not be redirected to the referrer and the 'execute' method are called during the POST action request?
– Kamil Szmit
Jan 9 at 14:15
add a comment |
To create AJAX action for POST requests in Magento 2.3, Please see the code below.
namespace BillonPaymentControllerMultishipping;
class Initiation extends MagentoFrameworkAppActionAction
protected $resultPageFactory;
protected $jsonHelper;
/**
* Constructor
*
* @param MagentoFrameworkAppActionContext $context
* @param MagentoFrameworkJsonHelperData $jsonHelper
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoFrameworkJsonHelperData $jsonHelper
)
$this->resultPageFactory = $resultPageFactory;
$this->jsonHelper = $jsonHelper;
parent::__construct($context);
/**
* Execute view action
*
* @return MagentoFrameworkControllerResultInterface
*/
public function execute()
try
return $this->jsonResponse('your response');
catch (MagentoFrameworkExceptionLocalizedException $e)
return $this->jsonResponse($e->getMessage());
catch (Exception $e)
$this->logger->critical($e);
return $this->jsonResponse($e->getMessage());
/**
* Create json response
*
* @return MagentoFrameworkControllerResultInterface
*/
public function jsonResponse($response = '')
return $this->getResponse()->representJson(
$this->jsonHelper->jsonEncode($response)
);
The problem is that the method „execute” of parent class, which extends 'MagentoFrameworkAppActionAction', is not run. How to resolve this problem? How to do that the action not be redirected to the referrer and the 'execute' method are called during the POST action request?
– Kamil Szmit
Jan 9 at 14:15
add a comment |
To create AJAX action for POST requests in Magento 2.3, Please see the code below.
namespace BillonPaymentControllerMultishipping;
class Initiation extends MagentoFrameworkAppActionAction
protected $resultPageFactory;
protected $jsonHelper;
/**
* Constructor
*
* @param MagentoFrameworkAppActionContext $context
* @param MagentoFrameworkJsonHelperData $jsonHelper
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoFrameworkJsonHelperData $jsonHelper
)
$this->resultPageFactory = $resultPageFactory;
$this->jsonHelper = $jsonHelper;
parent::__construct($context);
/**
* Execute view action
*
* @return MagentoFrameworkControllerResultInterface
*/
public function execute()
try
return $this->jsonResponse('your response');
catch (MagentoFrameworkExceptionLocalizedException $e)
return $this->jsonResponse($e->getMessage());
catch (Exception $e)
$this->logger->critical($e);
return $this->jsonResponse($e->getMessage());
/**
* Create json response
*
* @return MagentoFrameworkControllerResultInterface
*/
public function jsonResponse($response = '')
return $this->getResponse()->representJson(
$this->jsonHelper->jsonEncode($response)
);
To create AJAX action for POST requests in Magento 2.3, Please see the code below.
namespace BillonPaymentControllerMultishipping;
class Initiation extends MagentoFrameworkAppActionAction
protected $resultPageFactory;
protected $jsonHelper;
/**
* Constructor
*
* @param MagentoFrameworkAppActionContext $context
* @param MagentoFrameworkJsonHelperData $jsonHelper
*/
public function __construct(
MagentoFrameworkAppActionContext $context,
MagentoFrameworkViewResultPageFactory $resultPageFactory,
MagentoFrameworkJsonHelperData $jsonHelper
)
$this->resultPageFactory = $resultPageFactory;
$this->jsonHelper = $jsonHelper;
parent::__construct($context);
/**
* Execute view action
*
* @return MagentoFrameworkControllerResultInterface
*/
public function execute()
try
return $this->jsonResponse('your response');
catch (MagentoFrameworkExceptionLocalizedException $e)
return $this->jsonResponse($e->getMessage());
catch (Exception $e)
$this->logger->critical($e);
return $this->jsonResponse($e->getMessage());
/**
* Create json response
*
* @return MagentoFrameworkControllerResultInterface
*/
public function jsonResponse($response = '')
return $this->getResponse()->representJson(
$this->jsonHelper->jsonEncode($response)
);
edited Jan 9 at 13:43
Piyush
4,81472055
4,81472055
answered Jan 9 at 12:48
Anuj SharmaAnuj Sharma
162
162
The problem is that the method „execute” of parent class, which extends 'MagentoFrameworkAppActionAction', is not run. How to resolve this problem? How to do that the action not be redirected to the referrer and the 'execute' method are called during the POST action request?
– Kamil Szmit
Jan 9 at 14:15
add a comment |
The problem is that the method „execute” of parent class, which extends 'MagentoFrameworkAppActionAction', is not run. How to resolve this problem? How to do that the action not be redirected to the referrer and the 'execute' method are called during the POST action request?
– Kamil Szmit
Jan 9 at 14:15
The problem is that the method „execute” of parent class, which extends 'MagentoFrameworkAppActionAction', is not run. How to resolve this problem? How to do that the action not be redirected to the referrer and the 'execute' method are called during the POST action request?
– Kamil Szmit
Jan 9 at 14:15
The problem is that the method „execute” of parent class, which extends 'MagentoFrameworkAppActionAction', is not run. How to resolve this problem? How to do that the action not be redirected to the referrer and the 'execute' method are called during the POST action request?
– Kamil Szmit
Jan 9 at 14:15
add a comment |
In Magento 2.3, controllers must implement MagentoFrameworkAppActionHttpPostActionInterface to be able to handle POST requests - https://devdocs.magento.com/guides/v2.3/extension-dev-guide/routing.html
Adding 'implements MagentoFrameworkAppActionHttpPostActionInterface' to the parent class, which extends 'MagentoFrameworkAppActionAction', and to child class, which corresponds to the controller action, change nothing. What should I change additionally?
– Kamil Szmit
Jan 9 at 15:01
add a comment |
In Magento 2.3, controllers must implement MagentoFrameworkAppActionHttpPostActionInterface to be able to handle POST requests - https://devdocs.magento.com/guides/v2.3/extension-dev-guide/routing.html
Adding 'implements MagentoFrameworkAppActionHttpPostActionInterface' to the parent class, which extends 'MagentoFrameworkAppActionAction', and to child class, which corresponds to the controller action, change nothing. What should I change additionally?
– Kamil Szmit
Jan 9 at 15:01
add a comment |
In Magento 2.3, controllers must implement MagentoFrameworkAppActionHttpPostActionInterface to be able to handle POST requests - https://devdocs.magento.com/guides/v2.3/extension-dev-guide/routing.html
In Magento 2.3, controllers must implement MagentoFrameworkAppActionHttpPostActionInterface to be able to handle POST requests - https://devdocs.magento.com/guides/v2.3/extension-dev-guide/routing.html
answered Jan 9 at 12:57
PaulPaul
1,13211426
1,13211426
Adding 'implements MagentoFrameworkAppActionHttpPostActionInterface' to the parent class, which extends 'MagentoFrameworkAppActionAction', and to child class, which corresponds to the controller action, change nothing. What should I change additionally?
– Kamil Szmit
Jan 9 at 15:01
add a comment |
Adding 'implements MagentoFrameworkAppActionHttpPostActionInterface' to the parent class, which extends 'MagentoFrameworkAppActionAction', and to child class, which corresponds to the controller action, change nothing. What should I change additionally?
– Kamil Szmit
Jan 9 at 15:01
Adding 'implements MagentoFrameworkAppActionHttpPostActionInterface' to the parent class, which extends 'MagentoFrameworkAppActionAction', and to child class, which corresponds to the controller action, change nothing. What should I change additionally?
– Kamil Szmit
Jan 9 at 15:01
Adding 'implements MagentoFrameworkAppActionHttpPostActionInterface' to the parent class, which extends 'MagentoFrameworkAppActionAction', and to child class, which corresponds to the controller action, change nothing. What should I change additionally?
– Kamil Szmit
Jan 9 at 15:01
add a comment |
For future reference,
I was only able to make my request work by doing the following steps in Magento 2.3.1 otherwise I was getting a 404. I checked class vendor/magento/module-authorizenet/Controller/Directpost/Payment/BackendResponse.php
for reference.
- Add the following interfaces
CsrfAwareActionInterface, (especially important because all post requests are using by default CSRF validation)
HttpGetActionInterface,
HttpPostActionInterface
- Implement the CSRF handling functions
public function validateForCsrf(RequestInterface $request): ?bool
return true;
public function createCsrfValidationException(
RequestInterface $request
): ?InvalidRequestException
return null;
- Execute
php bin/magento setup:upgrade
php cache:flush
add a comment |
For future reference,
I was only able to make my request work by doing the following steps in Magento 2.3.1 otherwise I was getting a 404. I checked class vendor/magento/module-authorizenet/Controller/Directpost/Payment/BackendResponse.php
for reference.
- Add the following interfaces
CsrfAwareActionInterface, (especially important because all post requests are using by default CSRF validation)
HttpGetActionInterface,
HttpPostActionInterface
- Implement the CSRF handling functions
public function validateForCsrf(RequestInterface $request): ?bool
return true;
public function createCsrfValidationException(
RequestInterface $request
): ?InvalidRequestException
return null;
- Execute
php bin/magento setup:upgrade
php cache:flush
add a comment |
For future reference,
I was only able to make my request work by doing the following steps in Magento 2.3.1 otherwise I was getting a 404. I checked class vendor/magento/module-authorizenet/Controller/Directpost/Payment/BackendResponse.php
for reference.
- Add the following interfaces
CsrfAwareActionInterface, (especially important because all post requests are using by default CSRF validation)
HttpGetActionInterface,
HttpPostActionInterface
- Implement the CSRF handling functions
public function validateForCsrf(RequestInterface $request): ?bool
return true;
public function createCsrfValidationException(
RequestInterface $request
): ?InvalidRequestException
return null;
- Execute
php bin/magento setup:upgrade
php cache:flush
For future reference,
I was only able to make my request work by doing the following steps in Magento 2.3.1 otherwise I was getting a 404. I checked class vendor/magento/module-authorizenet/Controller/Directpost/Payment/BackendResponse.php
for reference.
- Add the following interfaces
CsrfAwareActionInterface, (especially important because all post requests are using by default CSRF validation)
HttpGetActionInterface,
HttpPostActionInterface
- Implement the CSRF handling functions
public function validateForCsrf(RequestInterface $request): ?bool
return true;
public function createCsrfValidationException(
RequestInterface $request
): ?InvalidRequestException
return null;
- Execute
php bin/magento setup:upgrade
php cache:flush
answered Jun 10 at 7:25
gabtzigabtzi
237210
237210
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f257261%2fhow-to-create-ajax-action-for-post-requests-in-magento-2-3%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown