代码之家  ›  专栏  ›  技术社区  ›  vondip

Internet Explorer ASHX文件问题

  •  2
  • vondip  · 技术社区  · 15 年前

    我的问题有点复杂: 我用c_,asp.net编写并使用jquery

    1. 我有一个页面发送请求到 使用jquery的ajax的服务器 方法。
    2. 我有一个ashx文件(处理程序)要 响应这些请求。
    3. 用户可以对 几页,然后用一些方法 这将调用ajax方法。
    4. 我的ashx文件从 会话变量和行为 因此。

    这在除Internet Explorer之外的所有浏览器中都可以正常工作。 在Internet Explorer中,会话似乎包含旧信息(旧用户ID)。令人难以置信的是,同样的代码在firefox、chrome和safari中运行良好,但在ie中失败了。

    是什么引起的?我不知道从哪里开始寻找解决办法。

    顺便说一句,对不起,总标题,不知道如何解释,只有几个字。

    以下是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);
            }
        });
    }
    

    阿什克斯

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

    谢谢您!

    2 回复  |  直到 11 年前
        1
  •  1
  •   Community CDub    8 年前

    你能说得更具体些吗?这里有一些可能出错的地方-是在浏览器上缓存,还是在服务器上调试时,它是否显示会话的旧值?

    确保将jquery.ajax调用的cache选项设置为false。你可能也想看看 this question and answer 关于ie的ajax缓存的攻击性。

        2
  •  1
  •   RckLN    11 年前

    只需在false中使用cache参数。

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

    Example Fiddle

    推荐文章