Safari Session Session Variables for iOS 6 Not Saved When Installed Through AJAX

Possible duplicate:
Is Safari on iOS 6 caching $ .ajax results?

I am having a problem with session variables set via AJAX in the Safari iOS 6 mobile browser. I have included a sample that will set the session variable, redirect to another page, refuse the session and start all over. This works fine 2 times. The third time, session variables are lost through the process. The problem only occurs in iOS 6 safari. It works in all other browsers that I have tried.

The sample consists of 3 pages. Page1 sets the session variable and redirects to page 2. Page 2 displays the session variable. Cancels a session variable.

Page 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> 

Page 1 Javascript:

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

Page 1 Code:

 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; } } } 

Page 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> 

Page 2 Code:

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

Page 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> 

Page 3 Code:

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

I found out that this is a problem because ajax requests and responses are cached in iOS6 Safari, so instead of sending a request to the server, it uses cached requests. to exceed this, just add a timestamp in your Ajax requests, it will work fine. I put the code that I used while updating my code with this. hope helps you.

This is a new variable to overcome this problem: parameters .timeStamp = new Date (). 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(); }) }); 

thanks

+5
source

Source: https://habr.com/ru/post/1435990/


All Articles