我有一个 onclicks 打开的弹出模式,我希望在提交表单并获得 ajax 成功请求时关闭此模式。我试过
success: function(data)
{
//console.log('ticket added');
this.closeModal();
}
但是它不起作用,任何人都可以解决这个问题。提前致谢
<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>
最佳答案
我得到了解决方案,我们可以使用以下代码行销毁模态。
$('#events_popup').modal('closeModal');
关于javascript - ajax 响应弹出模式关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43842565/