I have a popup modal that opens onclicks, I want this modal to be closed when I submit the form and get ajax success request. I tried using
success: function(data)
{
this.closeModal();
}
But it does not work, can anyone figure this out. Thanks at 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)
{
document.close();
}
});
e.preventDefault();
});
}
);
</script>
</div>
source
share