在初始化之前无法调用对话框上的方法;尝试在使用timeoutDialog插件时调用方法'close'

时间:2015-04-24 18:59:14

标签: jquery jquery-plugins

我正在尝试使用timeoutDialog插件为服务器实现一个简单的会话过期代码。对话框显示正确但单击任何按钮我在cannot call methods on dialog prior to initialization; attempted to call method 'close'中收到错误〜/static/js/jquery-1.8.2.min.js line 2 > eval。有人可以帮帮我吗?

这是我的代码块:

jQuery(function($) {
    var timeout = 10000;

    $(document).bind("idle.idleTimer", function() {
        // function you want to fire when the user goes idle
        $.timeoutDialog({ timeout: 1,
                          countdown: 10,
                          logout_redirect_url: '/logout/',
                          keep_alive_url:'/',
                          restart_on_yes: true });
        });
        $(document).bind("active.idleTimer", function() {
            // function you want to fire when the user becomes active again
        });
        $.idleTimer(timeout);
    });

    <script src="${request.static_url('static/js/timeout-dialog.js')}"></script>
    <script src="${request.static_url('static/js/idle-timer.js')}"></script>

2 个答案:

答案 0 :(得分:0)

我尝试了很多选择。看起来timeoutDialog插件不能正确支持更高版本的jQuery。 Example在这里解决了我的问题。

答案 1 :(得分:0)

** 在timeout-dialog.js文件中修改此行

destroyDialog: function () {
            if ($("#timeout-dialog").length) {
                $("#timeout-dialog").dialog("close");
                $('#timeout-dialog').remove();
            }
        },

**