2010-04-13 44 views
2

我的問題是有點複雜: 我寫在C#,asp.net和使用jqueryInternet Explorer中的ashx文件的問題

  1. 我有一個使用jQuery的AJAX 方法將請求發送到 服務器頁面。
  2. 我有一個ashx文件(處理程序)到 迴應這些請求。
  3. 用戶可以在 多個頁面上執行多項更改,然後使用一些方法 ,這些方法將調用ajax方法。
  4. 我的ashx文件從 會話變量中讀取一些值並相應地執行 。

這適用於所有瀏覽器,但在Internet Explorer中正常工作。 在Internet Explorer中,會話似乎保存舊信息(舊用戶ID)。這是令人難以置信的,相同的代碼在Firefox,鉻和Safari瀏覽器中工作正常,但與ie失敗。

什麼可能導致它?我不知道哪裏可以開始尋找解決方案。

btw,對不起,一般的標題,無法弄清楚如何用幾句話來解釋。

這裏是jQuery代碼和ASHX:

jQuery的

function SendRequstToServer(actionId, additional, callback) { 
    if (actionId == "-1") { 
     document.location = "default.aspx"; 
    } 
    $.ajax({ url: "SmallRoutinesHandler.ashx", method: "GET", 
    //asyn: false, 
     data: "Action=" + actionId + additional, 
     contentType: "string", 
     error: function(xhr, status, errorThrown) { 
      alert(errorThrown + '\n' + status + '\n' + xhr.statusText); 
     }, 
     success: function(data) { 
      alert(data); 
      callback(data); 
     } 
    }); 
} 

ASHX

context.Response.ContentType = "text/plain"; 
action = context.Request.QueryString["Action"]; 
switch ((ClientSideActionsRequest)Enum.Parse(typeof(ClientSideActionsRequest), action)) 
{ 
    case ClientSideActionsRequest.ShowProducts: 
    long userId = WebCommon.CurrentlyWatchedUser.Id; 
    List<UserItems> userItems = UserItems.GetByUserId(userId); 
    string[] items = HtmlWrapper.WrapAsItems(userItems); 
    if (items.Length > 0) 
    { 
     context.Response.Write(items.Aggregate((current, next) => string.Format("{0} , {1}", current, next))); 
    } 
    break; 
} 

謝謝!

+0

你能粘貼的背後與此問題相關的重要的ashx的代碼? – 2010-04-13 20:17:52

回答

1

你能更具體嗎?有幾種可能的事情在這裏可能會出錯 - 是在瀏覽器上緩存,還是在服務器上進行調試時,是否顯示Session的舊值?

確保您將jQuery .ajax調用的緩存選項設置爲false。您可能還想看到this question and answer關於IE的ajax緩存的攻擊性。

+0

@womp。謝謝。你爲我節省了很多時間。真的非常感謝你:) – vondip 2010-04-13 20:31:18

1

您只需在false中使用緩存參數。

$.ajax({ 
    url: "url", 
    cache: false, 
    .... 

Example Fiddle