【问题标题】:How to show Bootstrap Modal after fire jQuery function触发jQuery函数后如何显示Bootstrap Modal
【发布时间】:2016-09-20 06:17:35
【问题描述】:

火灾后如何显示Bootstrap Modal jQuery function

这是我的功能

$(".add-to-fav").click(function () {
                event.stopPropagation();
                event.preventDefault();
                var id = $(this).attr('id');
                var is_favorite;

                if ($(this).hasClass('glyphicon-star-empty')) {
                    $(this).removeClass('glyphicon-star-empty').addClass('glyphicon-star');
                    is_favorite = 1;
                } else {
                    $(this).removeClass('glyphicon-star').addClass('glyphicon-star-empty');
                    is_favorite = 0;
                }

                jQuery.ajax({
                    type: "POST",
                    url: "<?php echo base_url(); ?>" + "files" + "/" + "add_favorite",
                    dataType: 'json',
                    data: {selected_id: id, is_favorite: is_favorite},
                    success: function (res) {
                        if (res)
                        {
                            $("div#result").show();
                            $("div#value").html(res.id);
                            $("div#value").html(res.is_favorite);
                        }
                    }
                });

                location.reload(true);

            });

功能正常运行。 我想在触发location.reload(true); 之前显示带有重新加载gif 的模态@

谢谢。

【问题讨论】:

  • 不要做 ajax 并重新加载
  • 为什么?但我想发送ajax请求。功能正常。
  • 为什么要创建 ajax?
  • 如果我在视图中点击了收藏按钮,则使用 ajax 将点击的表格行 id 发送到控制器
  • 你为什么不做一个简单的get/post请求?

标签: jquery twitter-bootstrap bootstrap-modal reload


【解决方案1】:

要显示引导模式,请执行以下操作

$('#loading-modal').modal('show');

【讨论】:

  • 你把模态的id改成你的模态的id了吗?
  • 我在location.reload(true);之前扔了
  • 在 event.preventDefault() 之后添加;
  • 我试过了,但是我的功能不工作了。感谢您的支持。
  • 注意:ajaxStart 是一个全局函数,如果你有多个 ajax 请求它会触发模态,你可以使用 ajax 的 beforeSend 属性来触发模态,或者我告诉你你可以把ajax 调用前的模态显示
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-30
  • 2014-10-23
  • 1970-01-01
  • 2017-03-30
  • 2021-07-11
相关资源
最近更新 更多