I have a popup modal which onclicks opens , I want this modal to be closed when I submit the form and get the ajax success request. I tried with
success: function(data)
{
//console.log('ticket added');
this.closeModal();
}
But it is not working , can anyone sort this out. Thanks in Advance
<script>
require(
[
'jquery',
'Magento_Ui/js/modal/modal'
],
function(
$,
modal
) {
var options = {
type: 'popup',
responsive: true,
innerScroll: true,
title: 'Test title',
buttons: [{
text: $.mage.__('Continue'),
class: '',
click: function () {
this.closeModal();
}
}]
};
var popup = modal(options, $('#events_popup'));
$("#click-me").on('click',function(){
$("#events_popup").modal("openModal");
});
}
);
</script>
<div id="events_popup" style="display: none;" class="events_popup">
<script type="text/javascript">
require(
[
'jquery'
],
function($,modal)
{
$("#<?php echo $_product->getId()?>").submit(function(e) {
$.ajax({
type: "POST",
url: $(this).attr('action'),
data: $("#<?php echo $_product->getId()?>").serialize(),
showLoader: true,
success: function(data)
{
//console.log('ticket added');
document.close();
}
});
e.preventDefault();
});
}
);
</script>
</div>
Best Answer
Try this
This is your final answer