mvc2 与 ajax 表启用后退按钮
我已经创建了具有搜索表单的应用程序,下面包含搜索结果。 现在我希望能够添加历史记录、按钮返回功能。
问题是我陷入了加载页面的不定式循环中,我不知道为什么,这是在 FireFox 中。
我已按照本教程操作如何执行此操作:
http://www. asp.net/mvc/tutorials/contact-manager/iteration-7-add-ajax-functionity-cs
我的代码是:
Javascript
<% =Html.JQuery() %>
<script src="../../../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script type="text/javascript">
var _currentCaseId = -1;
Sys.Application.add_init(pageInit);
function OnBegin() {
var caseId = $("#SelectDeceased_hidden").val();
Sys.Application.addHistoryPoint({ "caseId": caseId });
$(document).ready(function () {
$("#divTableContainer").html("");
});
}
function OnSuccess() {
$('#divTableContainer').fadeIn('slow');
}
function OnFailure() {
alert("Something went wrong. Try again...");
}
function pageInit() {
// Enable history
Sys.Application.set_enableHistory(true);
// Add Handler for history
Sys.Application.add_navigate(navigate);
}
function navigate(sender, e) {
// Get groupId from address bar
var caseId = e.get_state().caseId;
// if cases does not match
if (_currentCaseId != caseId) {
// assign the case id
_currentCaseId = caseId;
alert(caseId);
$(document).ready(function () {
$.ajax({
url: "/PostItems/UmiTable?currentCase="
+ _currentCaseId
+ "&EntityType=-1",
success: function (data) {
$("#divContactList").text(data);
}
});
});
}
}
和我的 html
<% using (Ajax.BeginForm("UmiTable", new AjaxOptions() {
OnFailure = "OnFailure",
OnBegin = "OnBegin",
LoadingElementId = "divLoading",
UpdateTargetId = "divTableContainer" })) %>
<% { %>
<% using (Html.MooseFieldWrapper("Find case", "StandardForm"))
{ %>
<%= Html.CutomTextBox("Case") %>
<li class="Button"><input type="submit" value="Go" /></li>
<% } %>
<% } %>
<div id="divLoading">
<div><img src="Indicator.gif" alt="loading data" />Loading</div>
</div>
<div id="divTableContainer"></div>
I have created my application that has search form and below contains results for the search.
Now i want to be able to add history, button back functionality.
The problem is i am caught in infinitive loop of loading page and i am not sure why, this is in FireFox.
I have followed this tutorial how to do this:
http://www.asp.net/mvc/tutorials/contact-manager/iteration-7-add-ajax-functionality-cs
My code is:
Javascript
<% =Html.JQuery() %>
<script src="../../../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<script type="text/javascript">
var _currentCaseId = -1;
Sys.Application.add_init(pageInit);
function OnBegin() {
var caseId = $("#SelectDeceased_hidden").val();
Sys.Application.addHistoryPoint({ "caseId": caseId });
$(document).ready(function () {
$("#divTableContainer").html("");
});
}
function OnSuccess() {
$('#divTableContainer').fadeIn('slow');
}
function OnFailure() {
alert("Something went wrong. Try again...");
}
function pageInit() {
// Enable history
Sys.Application.set_enableHistory(true);
// Add Handler for history
Sys.Application.add_navigate(navigate);
}
function navigate(sender, e) {
// Get groupId from address bar
var caseId = e.get_state().caseId;
// if cases does not match
if (_currentCaseId != caseId) {
// assign the case id
_currentCaseId = caseId;
alert(caseId);
$(document).ready(function () {
$.ajax({
url: "/PostItems/UmiTable?currentCase="
+ _currentCaseId
+ "&EntityType=-1",
success: function (data) {
$("#divContactList").text(data);
}
});
});
}
}
And my html
<% using (Ajax.BeginForm("UmiTable", new AjaxOptions() {
OnFailure = "OnFailure",
OnBegin = "OnBegin",
LoadingElementId = "divLoading",
UpdateTargetId = "divTableContainer" })) %>
<% { %>
<% using (Html.MooseFieldWrapper("Find case", "StandardForm"))
{ %>
<%= Html.CutomTextBox("Case") %>
<li class="Button"><input type="submit" value="Go" /></li>
<% } %>
<% } %>
<div id="divLoading">
<div><img src="Indicator.gif" alt="loading data" />Loading</div>
</div>
<div id="divTableContainer"></div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
到底
我使用 jquery 历史脚本来管理导航。
in the end
i have used jquery history script to manage navigation.