2012-09-24 37 views
4

可能重複:
Is Safari on iOS 6 caching $.ajax results?的iOS 6移動Safari瀏覽器會話變量

我一直有通過AJAX在移動Safari瀏覽器的iOS 6設置會話變量的問題。我包括一個樣本,它將設置會話變量,重定向到另一個頁面,放棄會話並重新開始。這工作罰款前2次。在整個過程中第三次,會話變量會丟失。這個問題只發生在iOS 6 safari中。它適用於我嘗試過的所有其他瀏覽器。

樣本由3頁組成。 Page1設置會話變量並重定向到頁面2.頁面2顯示會話變量。放棄會話變量。

第1個HTML:

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
     <asp:ScriptManager ID="sm" runat="server" EnablePageMethods="true"> 
      <Scripts> 
       <asp:ScriptReference Path="~/Page1.js" /> 
      </Scripts> 
     </asp:ScriptManager> 
     <div onclick="setSessionVariable()">Set session variable and redirect to page 2</div> 
    </form> 
</body> 
</html> 

第1頁使用Javascript:

function setSessionVariable() { 
    PageMethods.SetSessionVariable(displaySetSessionVariable); 
} 

function displaySetSessionVariable(bReturn) { 
    window.location = "Page2.aspx"; 
} 

第1個代碼:

using System.Web.Services; 

namespace SafariSessionProblem { 
    public partial class Page1 : System.Web.UI.Page { 
     protected void Page_Load(object sender, EventArgs e) { 

     } 

     [WebMethod] 
     public static Boolean SetSessionVariable() { 
      System.Web.HttpContext.Current.Session["TestVariable"] = 1; 
      return true; 
     } 
    } 

} 

第2頁HTML:

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
     <asp:Label ID="lbl" runat="server" Text="Label"></asp:Label><br /><br /> 
     <div onclick="window.location = 'Page3.aspx'">Redirect to page 3 and abondon session</div> 
    </form> 
</body> 
</html> 

第2頁代碼:

namespace SafariSessionProblem { 
    public partial class Page2 : System.Web.UI.Page { 
     protected void Page_Load(object sender, EventArgs e) { 
      lbl.Text = Session["TestVariable"].ToString(); 
     } 
    } 
} 

第3頁HTML:

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
     <div onclick="window.location = 'Page1.aspx'">Start over</div> 
    </form> 
</body> 
</html> 

第3頁代碼:

namespace SafariSessionProblem { 
    public partial class Page3 : System.Web.UI.Page { 
     protected void Page_Load(object sender, EventArgs e) { 
      Session.Abandon(); 
     } 
    } 
} 
+0

我正在與iOS6的會話變量類似的問題.. – Kiran

回答

5

我必須弄明白的問題上,因爲iOS6的Safari瀏覽器緩存的Ajax請求,並響應,所以相反,發送請求到服務器它使用緩存的請求。爲了解決這個問題,只需將時間戳添加到Ajax請求中,它就可以正常工作。我已經放置了我使用過的代碼,在此幫助下更新了代碼。希望會對你有所幫助。

這是新的變量來克服這個問題parameters.timeStamp =新日期()的getTime();

parameters.qString = location.hash; 
parameters.timeStamp = new Date().getTime();//this new line for safari issue 

application.ajax({ 
    url: application.ajaxUrl + "ajax", 
    type: "post", 
    dataType: "json", 
    data: $.extend({method:parameters.method}, parameters), 
    success: function(response){ 
     stop_spinner(); 
      }) 
     }); 

感謝

+0

謝謝你,夥計,那固定.. – Kiran

+0

這解決了這一問題。感謝您的答覆。 – ebm256

相關問題