2

私はここから JQuery idleTimeout プラグインを使用しています:

http://www.erichynds.com/examples/jquery-idle-timeout/example-mint.htm

コードに実装すると問題なく動作しましたが、ページを起動するたびに毎回5 回更新されるため、idleTimeout コードを削除して確認しました。そして、それはこの問題を与えていませんでした。

詳細を調べた後、コードの " " 行を削除またはコメントするとpollingInterval:2、すべてが正常に機能し、更新の問題が解消され、タイムアウト機能が引き続き機能することがわかりました。

pollingInterval:2誰かが実際に何をしているのかを理解するのを手伝ってもらえますか?

プラグインのコードは次のとおりです

JS:

 <script type="text/javascript">
        // setup the dialog
        $("#dialog").dialog({
            autoOpen: false,
            modal: true,
            width: 400,
            height: 210,
            closeOnEscape: false,
            draggable: false,
            resizable: false,
            buttons: {
                'Yes, Keep Working': function () {
                    $(this).dialog('close');
                },
                'No, Logoff': function () {
                    // fire whatever the configured onTimeout callback is.
                    // using .call(this) keeps the default behavior of "this" being the warning
                    // element (the dialog in this case) inside the callback.
                    $.idleTimeout.options.onTimeout.call(this);
                }
            }
        });

        // cache a reference to the countdown element so we don't have to query the DOM for it on each ping.
        var $countdown = $("#dialog-countdown");

        // start the idle timer plugin
        $.idleTimeout('#dialog', 'div.ui-dialog-buttonpane button:first', {
            idleAfter: 600,
            pollingInterval: 2, //<--- THIS IS CAUSING ISSUE
            serverResponseEquals: 'OK',
            onTimeout: function () {
                window.location = "/Home/Index/";
            },
            onIdle: function () {
                $(this).dialog("open");
            },
            onCountdown: function (counter) {
                $countdown.html(counter); // update the counter
            }
        });

</script>

それが生成するダイアログボックス、

<!-- Session Time Out Message box -->
<div id="dialog" title="Your session is about to expire!">
    <p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 50px 0;"></span>You will be logged off in <span id="dialog-countdown" style="font-weight: bold"></span>seconds. </p>
    <p>Do you want to continue your session?</p>
</div>

追加する必要がある 2 つの Jquery は次のとおりです。

http://www.erichynds.com/examples/jquery-idle-timeout/src/jquery.idletimer.js
http://www.erichynds.com/examples/jquery-idle-timeout/src/jquery.idletimeout.js

他に必要な情報があれば教えてください!

提案してください!

4

1 に答える 1

2

私は自分の問題の解決策を見つけることができたので、それを共有することを考えました:

問題は、コード行が欠落していたことです。keepAliveURL: '/Home/KeepAlive'

            $.idleTimeout('#dialog', 'div.ui-dialog-buttonpane button:first', {
                idleAfter: 600,
                keepAliveURL: '/Home/KeepAlive',
                pollingInterval: 2,
                serverResponseEquals: 'OK',
                onTimeout: function () {
                    window.location = "/Home/Index/";
                },
                onIdle: function () {
                    $(this).dialog("open");
                },
                onCountdown: function (counter) {
                    $countdown.html(counter); // update the counter
                }
            });

この行に従って、「serverResponseEquals:」が「OK」という応答を探していたので、「OK」というメッセージを返します。私のコードはMVCにあるので、「ホーム」コントローラーの下に「OK」を返すContentClassを作成しました。

   public ContentResult KeepAlive()
        {
            return Content("OK");
        }

そしてそれはうまくいきました、私のページは更新を停止しました!

問題を調査していただきありがとうございます。

于 2013-10-23T21:53:36.880 に答える