0
我想以5秒的間隔刷新頁面,該頁面應該使用來自SQL Server的最新數據更新視圖。以下是代碼。使用AJAX和JQuery以設定的時間間隔自動刷新頁面
@model Test.Data.Domain.ManufacturingCdMachine
@{
ViewBag.Title = "Rimage Details";
ViewBag.JobId = Model.CurrentManufacturingJobId;
}
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" id="navbar">
<div class="container">
<div class="navbar-header">
</div>
</div>
</div>
<div id="CdMachineDetails">
@if (@Model.CurrentManufacturingJobId != null)
{
<div>
@{Html.RenderPartial("_CdMachineJob");}
</div>
}
else
{
<div>
@{Html.RenderPartial("_MachineInIdle");}
</div>
}
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
</body>
</html>
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
$(document).ready(
function() {
setInterval(function() {
var randomnumber = Math.floor(Math.random() * 100);
$.ajax({
type: "GET",
url: "/Mobile/CdMachine/Details/" + @Model.ManufacturingCdMachineId,
data: {
},
success: function (result) {
//Sets your content into your div
$('#CdMachineDetails').html(result);
}
});
}, 5000);
});
</script>
我的網頁的URL是http://localhost:28886/Mobile/CdMachine/Details/1
但是似乎頁面沒有讓人耳目一新。我究竟做錯了什麼?
-Alan-
變量結果是什麼包含 – gaetanoM
請嘗試在'success'中添加'console.log(result)'並告訴我們輸出是什麼。 –
那麼,http:// localhost:28886對於URL來說不是太有用。也許你把它放在網上的某個地方?或者甚至更好地在這裏創建一個可運行的代碼。 –