我使用ASP的MVC 4與jQuery 1.10.2AJAX功能只更新
我試圖更新的局部視圖中的表和調試的JavaScript似乎是類似於巫術沿(至少我以任何方式)。
在第一次調用我的ajax函數時,更新按預期發生。任何後續的呼叫都沒有註冊。
我已閱讀了幾篇文章和計算器的答案,其中包括設置cache = false
,閱讀開發人員工具中的網絡選項卡以瞭解發生的情況。
從第二個建議我可以看到第一個呼叫返回200
狀態響應,但第二個呼叫似乎什麼都不做。
我已經在腳本中放置了警報框,在第一次調用時,所有顯示和數據更新,但在第二次調用時什麼也沒有發生,爲什麼?
腳本
$("#resultsPerPage").change(function() {
alert("pre")
var selectedText = parseInt($(this).find(":selected").text())
call_PropertyTable("", 1, selectedText);
alert("post")
})
//calls _PropertyTable Partial view
function call_PropertyTable(param, val, resultsPerPage) {
$("#hdnCurrentPage").text(val);
alert("pre-ajax")
$.ajax({
cache: false,
url: "_PropertyTable",
type: "get",
data: { 'param': param, 'value': val, 'resultsPerPage': resultsPerPage },
success: function (data) {
$("#properties").html(data);
}
});
alert("post-ajax")
}
視圖
<div id="properties">
@{Html.RenderPartial("_PropertyTable", Model);}
</div>
局部視圖
//^^^other data not updating after first ajax call^^^
<select id="resultsPerPage" name="dataTables-example_length" aria-controls="dataTables-example" class="form-control input-sm">
<option value="10" @{if (ViewBag.PageRange == 10) { ViewBag.Selected = "selected"; } else { ViewBag.Selected = ""; }} @ViewBag.Selected>10</option>
<option value="25" @{if (ViewBag.PageRange == 25) { ViewBag.Selected = "selected"; } else { ViewBag.Selected = ""; }} @ViewBag.Selected>25</option>
<option value="50" @{if (ViewBag.PageRange == 50) { ViewBag.Selected = "selected"; } else { ViewBag.Selected = ""; }} @ViewBag.Selected>50</option>
</select> records per page
控制器
public ActionResult _PropertyTable(string param, int value = 1, int resultsPerPage = 10)
{
ViewBag.PageRange = resultsPerPage;
//other stuff
return PartialView(properties);
}
工作,謝謝。只需重新閱讀文檔,這對我來說是沒有意義的。我現在明白了....我認爲 – tony09uk
@ tony09uk,你的很多其他代碼並不理想。現在沒時間了,但我會稍後更新答案並提供一些其他建議。 –
謝謝。我知道我還有很長的路要走,任何建議都非常有趣。 – tony09uk