2017-05-08 67 views
4

我有一個彈出窗口模式,onclicks打開,我想這個模式被關閉,當我提交表單並獲得ajax成功請求。我試過彈出模式關閉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> 

回答

1

你試過

$('#yourmodalid').modal('hide'); 
+1

**從審覈隊列**:我可以請求您請您在答案中添加更多的上下文。僅有代碼的答案很難理解。如果您可以在帖子中添加更多信息,它可以幫助提問者和未來的讀者。 – RBT

+0

我試過你的解決方案,但得到一個錯誤。 – Verdu

1

我得到了解決,我們可以破壞與下面的代碼行的模式。

$('#events_popup').modal('closeModal');