"立即刷新"按钮工作,但"自动刷新"没有按'吨
<br /><br />
<a id="button" title="Refresh now">Refresh Now</a>
<a id="toggleButton" title="Auto refresh every 5 seconds">Auto Refresh</a>
<script type="text/javascript">
var autoRefresh = false;
var autoRefreshInterval = 1000 * 5;
这是&#34;立即刷新&#34;功能。它就像一个刷新按钮。
$(document).ready(function () {
$('a#button').click(function () {
$('#PartialDiv').load('@Url.Action("RefreshLiveContent", "ThreadClass", new { id = (int)ViewBag.SelectedThreadClassThreadID })'); //, new { id = (int)ViewBag.SelectedThreadClass}
});
这是自动刷新功能
$('a#toggleButton').click(function () {
$('#PartialDiv').Load('@Url.Action("RefreshLiveContent", "ThreadClass", new { id = (int)ViewBag.SelectedThreadClassThreadID })'); //, new { id = (int)ViewBag.SelectedThreadClass}
$(this).toggleClass("down");
if ($(this).is('.down')) {
autoRefresh = true;
} else {
autoRefresh = false;
}
});
var refresh = function () {
if (autoRefresh) {
$('#PartialDiv').Load('@Url.Action("RefreshLiveContent", "ThreadClass", new { id = (int)ViewBag.SelectedThreadClassThreadID })'); //new { id = (int)ViewBag.SelectedThreadClass}
}
setTimeout(refresh, autoRefreshInterval);
};
refresh();
});
</script>
<fieldset>
<legend>Test Live Content</legend>
<br />
<br />
<div id="PartialDiv">
@Html.Partial("LiveContent",Model)
</div>
</fieldset>
我得到的错误是Uncaught TypeError:undefined不是函数。
答案 0 :(得分:1)
加载函数中有拼写错误?
$('#PartialDiv').Load('@Url.Action("Ref
应改为
$('#PartialDiv').load('@Url.Action("Ref