【问题标题】:Modal won't show programmatically模态不会以编程方式显示
【发布时间】:2019-03-16 21:06:10
【问题描述】:

我有一个按钮,点击时会显示模式。

按钮是:

    <button type="button" class="btn btn-primary assignRole" data-toggle="modal" data-target="#assignRole">
        New
    </button>

模态是:

 <div class="modal fade" id="assignRole" role="dialog">
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Assign New Client Role to Employee</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
            </button>
         </div>
         <div class="modal-body">
            <form class="form-group">
            </form>
            <div class="modal-footer">
               <button type="button" class="btn btn-warning" data-dismiss="modal">
               <span class='glyphicon glyphicon-remove'></span> Close
               </button>
               <button type="button" class="btn btn-success add-role-to-user" data-dismiss="modal">
               <span class='glyphicon glyphicon-check'></span> Add
               </button>
            </div>
         </div>
      </div>
   </div>
</div>

当手动单击按钮时,这些工作正常,但我希望模式在错误时显示。

我正在使用以下代码:

error: function(errors){
                setTimeout(function (){
                    $(".assignRole").click();
                    toastr.error('Validation error!', errors.responseJSON.message, {timeOut: 5000});
                }, 500);
        }

有人可以指出我哪里出错了。我正在使用 coreui 管理模板和 chrome。

【问题讨论】:

    标签: ajax laravel core-ui


    【解决方案1】:

    您可以尝试这种方法来显示您的模态,而不是触发单击按钮:

    $('#assignRole').modal('show');
    

    【讨论】:

    • 您能打开开发者控制台并分享您遇到的错误吗?
    • edit:1546 Uncaught ReferenceError: data is not defined at Object.error (edit:1546) at fire (jquery-2.2.4.js:3187) at Object.fireWith [as rejectWith] (jquery -2.2.4.js:3317) 在完成 (jquery-2.2.4.js:8759) 在 XMLHttpRequest. (jquery-2.2.4.js:9123)
    • 这个错误来自代码中的其他地方我的朋友,所以你需要先弄清楚,因为这会阻止稍后在另一部分的执行。
    • 我已经解决了错误,现在我在控制台中得到“422(无法处理的实体)”。不过吐司会显示。
    • 这意味着您的 ajax 请求仍然不正确,因为您传递的数据是错误的。您可以找到许多 422 错误的答案。但是模式应该出现取决于您使用的是哪个模式,是按钮单击还是modal('show') 调用?
    【解决方案2】:

    $('#assignRole').modal('show');之前添加jQuery.noConflict();后终于成功了。

    更多详情here.

    【讨论】:

      猜你喜欢
      • 2015-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-05
      • 2011-10-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多