javascript - 从服务器获得响应后关闭 Controller 中的 Bootstrap 模式

标签 javascript angularjs twitter-bootstrap

提交表单后,将调用服务器并显示模式。当服务器响应成功时,必须关闭模态 并加载一个新页面。

我已经尝试过 ng-show、ng-if 来根据 Controller 中的值启用/禁用,但这并没有消除模态背景。我可以使用 data-dismiss="modal"关闭同一页面上的模式,但是在导航到新页面之前如何从 Controller 部分执行此操作?

<div id="myModal" class="modal fade" role="dialog" aria-hidden="true">
 <div class="modal-dialog">
  <div class="modal-content">    
    <img src="img/processing.gif" id="ajaxSpinnerImage" title="working...">
  </div>
</div>

点击提交按钮时

<button type="submit" data-toggle="modal" 
data-target="#myModal"  ng-click=" formsubmit(orderForm.$valid); ></i>  
Place Order </button>   

从 Controller 调用服务器

 $scope.formsubmit = function (isValid) {
      if (isValid) {                              
                  $http.post($scope.url).
                    success(function (data, status) {  

                        //NEED TO CLOSE THE MODAL HERE
                   //navigating to a new page now
                   window.location.assign("NewPageToNavigate.html");

                    })
      }                

最佳答案

将此 Bootstrap 模态选项连接到服务器响应,模态将关闭:

$('#myModal').modal('hide');

More info and options on the Bootstrap documentation .

关于删除 body 和 backdrop 类,请检查您的代码,因为在正常情况下 Bootstrap 应该在触发上述方法时删除它们。

关于javascript - 从服务器获得响应后关闭 Controller 中的 Bootstrap 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47943545/

相关文章:

jquery dotdotdot 插件(添加省略号)不适用于 Bootstrap 轮播

php - javascript : unexpected non-whitespace character after JSON data 中的 JSON 错误

javascript - Highchart Js 中的工具提示修改

html - 滚动时如何根据可见的内部 div 高度调整外部 div 高度

angularjs - 如何在Grails 2.5.3中使用ng-file-upload

css - 将 px 更改为 em bootstrap 3 SASS 版本

javascript - 非 ASCII 字符 '\xc5' 破坏 python 脚本

javascript - 文本选择出现在 Chrome 中的整个窗口中

AngularJS 测试替换设置为 true 的指令

css - 在特定页面上将 col-lg 的网格选项大小更改为 > 1400