我想显示一个加载屏幕,当用户点击一个按钮来执行一个动作,因为该动作需要10秒钟运行。在MVC等待屏幕4
我在家里控制器我有一个简单的HTTP发布:
[HttpPost]
public ActionResult PostMethod()
{
System.Threading.Thread.Sleep(1000);
return View();
}
在我看来,我有:
@{
ViewBag.Title = "Home Page";
}
@section featured {
<div id="divLoading" style="margin: 0px; padding: 0px; position: fixed; right: 0px; top: 0px; width: 100%; height: 100%; background-color: #666666; z-index: 30001; opacity: .8; filter: alpha(opacity=70);display:none">
<p style="position: absolute; top: 30%; left: 45%; color: White;">
Loading, please wait...<img src="../../Content/themes/base/images/ajax-loading.gif">
</p>
</div>
<section class="featured">
<div class="content-wrapper">
<hgroup class="title">
<h1>@ViewBag.Title.</h1>
<h2>@ViewBag.Message</h2>
</hgroup>
</div>
</section>
}
<button onclick="JavascriptFunction();">HTTPPost Button</button>
<script type="text/javascript" language="javascript">
function JavascriptFunction() {
var url = '@Url.Action("PostMethod", "Home")';
$("#divLoading").show();
$.post(url,function (res) {
$("#content-wrapper").html(res);
$("#divLoading").fadeOut(100);
});
}
</script>
基本上Javascript函数显示“divLoading” DIV当用户点击按钮。这工作正常。问题在于,在睡眠1秒钟完成后,“divLoading”不会消失。所以屏幕就像加载时一样,它应该恢复正常。
是这样的:
return View()
线[HTTP]正常工作?或者是这条线:
$.post(url, null, function() {
//$("#PID")[0].innerHTML = data;
$("#divLoading").hide();
});
某处它不承认视图被返回,它不应该显示divLoading。
要调用隐藏 –
我把一个断点在返回查看你检查,如果你的JavaScript函数在执行时()行,当我执行它直接为无效格画面。我不去javascript的功能。 ()后面的 – user3022875
;放置像警报,并看看它是否出现 –