2012-05-03 49 views
4

我有一個與jQuery的移動應用程序的asp.net mvc 4。ajax鏈接處理不當

在一個頁面上(url:/ StatementBatch),我有一個批次列表,它們只是指向批次詳細信息頁面的鏈接(url:/ StetementBatch/Details/4)。

<li> 
    <a href="/StatementBatch/Details/4"> 
     <h3>January 2012</h3> 

     <div style="float: right; width: 30%;"><strong>Issued : </strong>1/10/2012 12:00:00 AM</div> 
     <div style="float: right; width: 30%;">Completed</div> 

     <p class="ui-li-aside"><strong>1277</strong></p> 
    </a> 


</li> 

的奇異之處在於,一旦鏈接被點擊,細節頁面呈現,現在的瀏覽器當前的URL是http://localhost:49457/StatementBatch#/StatementBatch/Details/4

我需要什麼,在應用更改得到這種行爲固定的嗎?

我的猜測是它的某種ajax加載相關的問題,但我的共享_Layout.cshtml文件包含$.mobile.ajaxEnabled = false;,我預計會殺死所有的ajax加載,但我顯然誤解了那一個。

謝謝!

回答

4

我懷疑這可能是答案

jQuery Mobile ajaxEnabled doesn't work?

將測試和查看更多信息如果我能使它工作

移動mobileinit綁定到jquery之後,但在jquery-mobile之前做的伎倆。這似乎是在MVC4的(新)移動Web應用程序模板,一個錯誤,這只是捆綁的所有腳本一起

這種失敗....

<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Content/css")" rel="stylesheet" type="text/css" /> 
<script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Scripts/js")"></script> 

<script> 
    $(document).bind("mobileinit", function() { 
     // As of Beta 2, jQuery Mobile's Ajax navigation does not work in all cases (e.g., 
     // when navigating from a mobile to a non-mobile page, or when clicking "back" 
     // after a form post), hence disabling it. 
     $.mobile.ajaxEnabled = false; 
    }); 
</script> 

但這個工程....

<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Content/css")" rel="stylesheet" type="text/css" /> 

<script src="../../Scripts/jquery-1.7.2.js" type="text/javascript"></script> 
<script src="../../Scripts/jquery-ui-1.8.11.js" type="text/javascript"></script> 

<script> 
    $(document).bind("mobileinit", function() { 
     // As of Beta 2, jQuery Mobile's Ajax navigation does not work in all cases (e.g., 
     // when navigating from a mobile to a non-mobile page, or when clicking "back" 
     // after a form post), hence disabling it. 
     $.mobile.ajaxEnabled = false; 
    }); 
</script> 

<script src="../../Scripts/jquery.mobile-1.1.0.js" type="text/javascript"></script> 
<script src="../../Scripts/jquery.unobtrusive-ajax.js" type="text/javascript"></script> 
<script src="../../Scripts/jquery.validate.js" type="text/javascript"></script> 
<script src="../../Scripts/jquery.validate.unobtrusive.js" type="text/javascript"></script> 
<script src="../../Scripts/modernizr-2.5.3.js" type="text/javascript"></script> 

謝謝...

0

這很奇怪。如果$.mobile.ajaxEnabled = false;被設置,那麼它不應該生成ajax鏈接。請檢查您的視圖是否正在使用啓用此設置的其他母版頁。在相應的視圖目錄下查找「_ViewStart.cshtml」,查看它鏈接到哪個主機。

爲了禁用特定超鏈接的Ajax行爲,使用data-ajax="false"屬性。像下面一樣

<a href="/StatementBatch/Details/4" data-ajax="false"> 
    <h3>January 2012</h3> 
    <div style="float: right; width: 30%;"><strong>Issued : </strong>1/10/2012 12:00:00 AM</div> 
    <div style="float: right; width: 30%;">Completed</div> 
    <p class="ui-li-aside"><strong>1277</strong></p> 
</a> 
+0

不,那$ .mobile。ajaxEnabled =來自主佈局頁面的假位IS。只有上面已經提到的那個....我已經知道如何做data-ajax =「false」......我更加好奇爲什麼ajax啓用的腳本似乎沒有做我認爲的應該... – reidLinden

1

這是您使用jQuery mobile時的默認行爲。 jQuery手機將使您的所有鏈接都被激活。這意味着它會通過ajax加載鏈接頁面的內容並更新url。如果要禁用鏈接被Ajax化的,你可以用external添加rel屬性作爲值

<a href="somepagep.aspx" rel="external">This will open without ajax</a> 

這會是一個正常的頁面打開,以便您的網址就會根據新的頁面上更新。

或者您可以使用data-ajax="false"以及

<a href="somepagep.aspx" data-ajax="false">This link also will open without ajax</a> 

此鏈接有一個關於它http://jquerymobile.com/test/docs/pages/page-links.html

+0

「$ .mobile.ajaxEnabled = false;」也是如此不進入它? – reidLinden

+0

這是一個全局級別的配置,用於禁用所有鏈接。添加這些屬性將禁用單個鏈接。 – Shyju

+0

頗爲明白。但真正的問題是,(如果我已經禁用了它們,我不應該在個別鏈接上禁用它)......通用禁用行爲(作爲新MVC移動設備中的默認配置項目)實際上並沒有禁用他們....我發佈了另一個答案,似乎它會變成正確的答案,但我正在努力能夠測試它.. – reidLinden