我正在 ASP.NET MVC 5 项目中实现Timeout-Dialog.js。
所以在我的布局页面上我有
<script type="text/javascript" language="javascript">
$(function () {
Timer();
});
function Timer() {
console.log("Set Timeout");
setTimeout(TimeOut, 10000);
}
function TimeOut() {
$.timeoutDialog({
timeout: 1,
countdown: 60,
keep_alive_url: '@Url.Action("KeepAliveSession", "Account")',
logout_redirect_url: '@Url.Action("Login", "Account")',
logout_url: '@Url.Action("LogOff", "Account")',
restart_on_yes: true
});
}
</script>
我将所有文件都包含在BundleConfig
。
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery-ui.min.js",
"~/Scripts/jquery.dataTables.min.js",
"~/Scripts/dataTables.jqueryui.min.js ",
"~/Scripts/timeout-dialog/js/timeout-dialog.js"
));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css",
"~/Content/main.css",
"~/Content/jquery.dataTables.min.css",
"~/Content/jquery-ui.css",
"~/Content/dataTables.jqueryui.min.css",
"~/Scripts/timeout-dialog/css/timeout-dialog.css"
));
对话框会及时显示,但是当我按下任何按钮时,我都会遇到此错误。
未捕获错误:在初始化之前无法调用对话框上的方法; 试图调用方法'关闭'
答案 0 :(得分:1)
请参阅: documentation
问题在于插件 Timeout-Dialog.js
将$(this).dialog('close')
替换为插件中的$('#timeout-dialog').dialog('close');