Javascript 无法调用js文件函数
我使用的是一个js文件,它在用户会话即将结束之前给我一个弹出窗口。我用两种方式使用这个文件 1) 在web窗体应用程序中,它工作得很好。下面是它的代码。 我正在跟踪链接Javascript 无法调用js文件函数,javascript,asp.net-mvc,session-timeout,Javascript,Asp.net Mvc,Session Timeout,我使用的是一个js文件,它在用户会话即将结束之前给我一个弹出窗口。我用两种方式使用这个文件 1) 在web窗体应用程序中,它工作得很好。下面是它的代码。 我正在跟踪链接 会话超时警告消息 功能计时器(时间){ setTimeout(超时,时间); } 函数超时(){ 警报(窗口、位置、路径名); $.timeoutDialog({ 超时:0.15, 倒计时:60, 保持\u活动\u url:window.location.pathname, 注销\重定向\ url:'/AutoSessionT
会话超时警告消息
功能计时器(时间){
setTimeout(超时,时间);
}
函数超时(){
警报(窗口、位置、路径名);
$.timeoutDialog({
超时:0.15,
倒计时:60,
保持\u活动\u url:window.location.pathname,
注销\重定向\ url:'/AutoSessionTimeOut/SessionTime.aspx',
在上重新启动\u是:真
});
}
cs代码:
if (!IsPostBack)
{
int _displayTimeInMiliSec = (Session.Timeout - 1) * 60000;
if (Session["ID"] == null)
{
Session["ID"] = "New Session";
lblMsg.Text = Convert.ToString(Session["ID"]);
}
else
lblMsg.Text = "Old Session";
ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(),
"message",
"<script type=\"text/javascript\" language=\"javascript\">Timer('" + _displayTimeInMiliSec + "');</script>",
false);
}
if(!IsPostBack)
{
int_displaytimeinmiliesec=(Session.Timeout-1)*60000;
if(会话[“ID”]==null)
{
会话[“ID”]=“新建会话”;
lblMsg.Text=Convert.ToString(会话[“ID”]);
}
其他的
lblMsg.Text=“旧会话”;
ScriptManager.RegisterClientScriptBlock(this.Page,this.Page.GetType(),
“信息”,
“计时器('”+_displaytimeinmiliesec+“);”,
假);
}
2) 我正在MVC应用程序中使用它
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js"></script>
<script src="Scripts/timeout-dialog.js"></script>
<link href="Content/timeout-dialog.css" rel="stylesheet" />
<script type="text/javascript">
function Timer(time) {
setTimeout(TimeOut, time);
}
function TimeOut() {
//window.location.pathname = '/Home/Index';
alert(window.location.pathname);
alert('hi');
$.timeoutDialog({
timeout: 0.25,
countdown: 30,
keep_alive_url: window.location.pathname,
logout_redirect_url: '/Home/Index',
restart_on_yes: true
});
}
</script>
</head>
<body onload="Timer(15000)">
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
@Html.Partial("_LoginPartial")
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @DateTime.Now.Year - My ASP.NET Application</p>
</footer>
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>
@ViewBag.Title-我的ASP.NET应用程序
@style.Render(“~/Content/css”)
@Scripts.Render(“~/bundles/modernizer”)
功能计时器(时间){
setTimeout(超时,时间);
}
函数超时(){
//window.location.pathname='/Home/Index';
警报(窗口、位置、路径名);
警报(“hi”);
$.timeoutDialog({
超时:0.25,
倒计时:30,
保持\u活动\u url:window.location.pathname,
注销\u重定向\u url:“/Home/Index”,
在上重新启动\u是:真
});
}
@ActionLink(“应用程序名称”、“索引”、“主页”、新{area=”“}、新{@class=“navbar品牌”})
- @ActionLink(“主页”、“索引”、“主页”)
- @ActionLink(“关于”、“关于”、“主页”)
- @ActionLink(“联系人”、“联系人”、“主页”)
@Html.Partial(“_LoginPartial”)
@RenderBody()
&抄袭@DateTime.Now.Year-我的ASP.NET应用程序
@Scripts.Render(“~/bundles/jquery”)
@Scripts.Render(“~/bundles/bootstrap”)
@RenderSection(“脚本”,必需:false)
在这里,当我在这一行$.timeoutDialog({
如上所述)前面放置一个警报时,警报会出现,但其余的代码不会执行,并且我不会在我的web表单应用程序中得到任何弹出窗口
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js"></script>
<script src="Scripts/timeout-dialog.js"></script>
<link href="Content/timeout-dialog.css" rel="stylesheet" />
<script type="text/javascript">
function Timer(time) {
setTimeout(TimeOut, time);
}
function TimeOut() {
//window.location.pathname = '/Home/Index';
alert(window.location.pathname);
alert('hi');
$.timeoutDialog({
timeout: 0.25,
countdown: 30,
keep_alive_url: window.location.pathname,
logout_redirect_url: '/Home/Index',
restart_on_yes: true
});
}
</script>
</head>
<body onload="Timer(15000)">
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
@Html.Partial("_LoginPartial")
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @DateTime.Now.Year - My ASP.NET Application</p>
</footer>
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>
我在
MVC
应用程序中做错了什么。请帮助。我认为timeout
参数应该是一个整数,正如前面提到的那样是不是所有的JS文件都被加载了?@Shil:我该如何检查呢?请使用类似于小提琴的工具。如果您使用的是Chrome web浏览器,请使用控制台在Chrome o中调试codePress F12也就是说,你可以调试我只是不明白,同样的代码在web表单中和在链接中一样可以正常工作,但在mvc中不工作。