加载后刷新浏览器或清除DOM [英] Refresh the browser once on load or clear DOM

查看:214
本文介绍了加载后刷新浏览器或清除DOM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态的MVC4,jQuery Mobile应用程序,在很大程度上可以很好地工作.我有一个自动发布下拉列表,它通过以下代码从数据库中选择一个列表.

I have a dynamic MVC4, jQuery Mobile application that works for the most part quite well. I have an auto posting dropdown list that selects a list from the database via the following code.

<script type="text/javascript">
    $(function () {
        $("#TownID").live('change', function () {
        //$("#TownID").change(function () {
            var actionUrl = $('#TheForm1').attr('action') + '/' + $('#TownID').val();
            $('#TheForm1').attr('action', actionUrl);
            $('#TheForm1').submit();
        });
    });
</script>

<p>
     @using (Html.BeginForm("SearchTown", "Home", FormMethod.Post, new { id = "TheForm1" }))
    {
        @Html.DropDownList("TownID", (SelectList)ViewBag.TownId, "Select a Town")
    }
</p>

问题在于,除非我单击刷新",否则它只有在第一次执行搜索时才能正常运行.我认为这与MVC没有任何关系,我认为问题出在AJAX和jQuery Mobile.

The problem is it only works properly the first time a search is performed unless I click refresh. I don’t think this has anything to do with MVC, I think the problem is with AJAX and jQuery Mobile.

我第一次搜索 www.mysite.com/Home/Search/2 时会产生结果并且可以正常工作,但是第二次似乎在DOM中遗留了一些东西???它会寻找:

The first time I search www.mysite.com/Home/Search/2 yields a result and woks fine, but the second time something seems to be left behind in the DOM??? and it looks for:

www.mysite.com/Home/Search/2/2 also

我的日志中出现404错误,并且显示错误加载页面" ,但它仍会找到结果并正确显示页面!

I get 404 errors in my log and "Error Loading Page" but it still finds the results and displays the page correctly!

然后通过第三次搜索,我在日志中看到错误404,并显示错误加载页面",但该错误已经扩大,现在查找:

Then with a third search I get the error 404’s in my log and "Error Loading Page" but it has grown and now looks for:

www.mysite.com/Home/Search/2/2
www.mysite.com/Home/Search/2/2/2 also

然后,每次搜索后这种情况都会继续增长,直到每次测试的某个看似随机的点,它似乎都放弃了,并且出现错误505

This then continues to grow after every search until at some seemingly random point on each test, it seems to give up and I get error 505

其他修改:

如果我将jQuery Mobile排除在外,该代码将完美运行

谁能告诉我这里可能会发生什么事?

Can anyone tell me what might be going on here?

推荐答案

我想这是未来的解决方案,MVC和jQuery Mobile似乎现在还不能完全融合.也许MS对这个问题的回答是单页应用程序"!

I guess this is one for the future, MVC and jQuery Mobile don't seem to blend completely right now. Maybe MS's response to the issue is Single Page Applications!

SPA还能满足Danial吗?

SPA may satisfy Danial also?

这篇关于加载后刷新浏览器或清除DOM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆