2010-07-08 173 views
0

我正在運行一個類似於this other thread中的問題,我缺少想法,所以我非常感謝任何幫助!(ASP classic)停止/阻止其他代碼執行而不會中斷Javascript執行

這是事情: 我們有一個ASP應用程序使用會話變量,並且必須處理會話合併由於多標籤(IE8)。

很多很多很多的嘗試之後,我來到了以下實現:

  1. 我設置於客戶端的ID給每個瀏覽器的標籤(我使用的是sessionStorage爲) 。

  2. 爲了使它在服務器端可用(因爲我找不到任何其他方式),我將它保存在cookie中並重新加載頁面。

  3. 最後,在我的ASP頁面上,我從cookie中獲取該ID並將其用作應用程序上所有會話變量的前綴。

這裏有一個簡單的例子

的Javascript(在每一個ASP文件的最開始插入)

LoadJs(); 

    // Cookie and TabID handler 
    function LoadJs() 
    { 
     if (getInternetExplorerVersion() <= 6) 
     { 
      //alert("Exit..... old browser version : " + getInternetExplorerVersion()); 
      return; 
     } 

     if (sessionStorage.TabID) 
     { 
      // Check value in cookie 
      var tabIdinCookie = readCookie("tabid"); 

      // if ID in cookie not the same as ID in session update cookie and 
      // refresh the page to update values in server-side 
      if(!tabIdinCookie || (tabIdinCookie && tabIdinCookie != sessionStorage.TabID)) 
      { 
       createCookie("tabid",sessionStorage.TabID); 
       ReloadPage(); 
      } 
     } 
     else 
     { 
      // Create random ID 
      var currentTime = new Date();  
      sessionStorage.TabID = currentTime.getTime(); 
      // Save ID to cookie 
      createCookie("tabid",sessionStorage.TabID); 
      createCookie("usingIE8",true,1); 

      // Refresh the page to make it available from server-side 
      ReloadPage(); 

     } 
     return true; 
    } 

    // Redirect to the same page to refresh data at server-side 
    function ReloadPage() 
    { 
     window.location.reload(true); 
    } 

然後,ASP代碼:

<% 
    Dim Nm 
    Nm="" 


response.Write("<br>Reading from cookie....") 

    if (Request.cookies("usingIE8") <> "")then 
     if (Request.cookies("tabid") = "") then 
      'response.Write("<br>No cookie") 
      'response.flush() 
      ' WHAT TO DO HERE ???? 
     else 
      Response.Write("<br>Cookie FOUND<br>") 
      Nm = Request.cookies("tabid") 
     end if 
    end if 




if (Session(Nm + "LogonTime")="") then 
    Response.Write("<br><b>Updating session</b><br>") 
    Session(Nm + "LogonTime") = Now 
    UpdateInDB(Session(Nm + "LogonTime")) 
    ' Do other stuffs 
end if 

%>


我正要終於得到一個解決方法的問題很驕傲,但我意識到,當一個頁面做一個POST操作,所有代碼ASP呈現(使用錯誤的前綴-ID)和執行(數據庫操作包括)在正確TabID可以在cookie上更新並且可以通過javascript重新加載頁面。我的意思是我所有的頁面代碼都被執行了兩次,之前和之後再次執行刷新...: - |

有沒有人認爲它可以實現smthg像一個Response.End(),以防止其餘的代碼ASP執行,如果我可以確定我必須刷新頁面而不殺死在同一時間的JavaScript執行?或者在網頁上的其他操作之前等待所有JavaScript執行?

我被困在這裏,它讓我哭,不得不在這裏停止!必須有一個解決方案...如果我能找到一個修復程序,它將被應用於許多ASP(3.0)應用程序,至少在3或5年之前不會升級到ASP.NET。

由於提前,

+0

另一種方法時,我會高興,如果能夠將捕捉到每一個請求的網頁上ASP腳本的執行之前更新餅乾! :-) .... 任何人 ? – Manotas 2010-07-09 08:16:37

+0

這意味着沒有其他事情要做? .....''( – Manotas 2010-07-12 08:21:10

回答

0

我沒有,但知道爲什麼大家都這樣做,而不是重新加載整個頁面,我會使用AJAX來設置會話變量?

確定,例如使用jQuery:

// AJAX Request 
$.post("session.asp", { act: "setSession", varName: "myVar", varValue: "myVal" }, 
    function(data) { 
    alert("new Session value: " + data); 
}); 

然後會話。ASP:

if request.form("act") = "setSession" then 
    session(request.form("varName")) = request.form("varValue") 
    ' now you have the new value in Session: 
    ' 
    response.write Session("myVar") 
end if 

希望這有助於

+0

您好ulluoink,感謝您的回覆.... 它可能是一個有趣的方法,但我必須承認,我不知道我怎麼能達到它...我可以使用jQuery圖像實例,但那麼我怎麼能更新會話變量?我會操縱一個ASP(不.NET)會話...你認爲這可能是可能的嗎? – Manotas 2010-07-19 10:03:02