无法在 cakephp 3 中加载模态弹出窗口

Cannot load modal popup in cakephp 3

我想在单击编辑时加载模态弹出窗口 link。但它需要新的页面。我使用了 e.preventDefault() 函数,但它不起作用。下面是我的代码。 它带我去 http://localhost/projectname/PanelAdmin/Products/edit/1。请帮助解决我的问题我是cakephp的新手。

View.ctp

<li>
          <?php              
          echo $this->Html->link("Edit Profucts","/PanelAdmin/Products/edit/".$prod->product_id, array('update' => '#flexModal','htmlAttributes' => array('data-toggle' => 'modal','data-target' => '#flexModal')));
              ?>
    </li> 

<script>
$(document).ready(function() {
    $("a[data-target=#flexModal]").click(function(ev) {
        ev.preventDefault();
        $("#flexModal .modal-body").load(target, function() {
            $("#flexModal").modal("show");
        });
    });
});
</script>

View: edit.ctp

<div class="modal" data-target="#flexModal" tabindex="-1" role="dialog" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title" id="myModalLabel"></h3>
            </div>
            <div class="modal-body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
            </div>
        </div>
    </div>
</div>

ProductsController.php

public function edit()
{
    $this->render('edit', 'ajax');
}

你应该用 ' 包装你的属性值,同时选择你的 link 元素它应该是 $("a[data-target='#flexModal']") 而不是这个 $("a[data-target=#flexModal]").

所以现在最终的js代码是这样的

$(document).ready(function() {
   $("a[data-target='#flexModal']").click(function(ev) {
       ev.preventDefault();
       $("#flexModal .modal-body").load(target, function() {
          $("#flexModal").modal("show");
       });
    });
});