how to use post method to contoller and phtml for button event in magento 2
-
27-02-2021 - |
Question
I have a button in phtml file
some.phtml
<button class="example-button-1 example-button-3 :active" type="button" id="acceptnow" ><span>Active</span></button>
I want to use post method to the controller for triggering the email
but how I do that???
Solution
You can do code like this :
<script type="text/javascript">
jQuery("#acceptnow").click(function(e)
{
var formurl = '<?php echo $this->getUrl('Vendor/Extension/Action'); ?>';
jQuery.ajax({
type: "POST",
url: formurl,
data:{variable:variable},
beforeSend: function()
{
//do Logic before ajax request start
},
success: function(transport)
{
//Do Logic when sucess comes
},
error: function()
{
//Do Logic when error into request
}
});
});
</script>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange