【问题标题】:Can jQuery be used to remove an HTTP response header?可以使用 jQuery 来删除 HTTP 响应标头吗?
【发布时间】:2013-08-16 06:58:24
【问题描述】:

我正在设计一个 MVC 视图,该视图将使用 how to auto refresh MVC PartialView every second 中描述的技术使用 AJAX 自动刷新部分视图。

只要客户端启用了 javasript,这应该可以正常工作,但我也会撒谎以支持非 JavaScript 客户端的自动刷新(整个页面)。

所以我想使用自定义AutoRefreshAttribute 在父操作方法中设置 refresh 标头:

public class AutoRefreshAttribute : ActionFilterAttribute
{
    public AutoRefreshAttribute(int waitSeconds)
    {
        this.WaitSeconds = waitSeconds;
    }

    public int WaitSeconds { get; set; }

    public override void OnResultExecuted(ResultExecutedContext filterContext)
    {
        filterContext.HttpContext.Response.AppendHeader(
            "refresh", 
            this.WaitSeconds.ToString());

        base.OnResultExecuted(filterContext);
    }
}

[AutoRefresh(30)]
public ViewResult Index()
{
    return this.View();
}

然后我想写一些在索引视图加载后执行的 jQuery;这应该删除 refresh 标头,因此如果客户端启用了 javascript,则不会刷新整个页面。然后我可以允许使用 AJAX 自动刷新部分视图。

是否可以使用 jQuery 删除 HTTP 响应标头?

【问题讨论】:

    标签: c# asp.net-mvc jquery httpresponse


    【解决方案1】:

    不,这是不可能的。在处理任何 javascript 之前很久就已经读取了 HTTP 标头。

    【讨论】:

      猜你喜欢
      • 2016-08-29
      • 1970-01-01
      • 2017-01-18
      • 2011-12-15
      • 1970-01-01
      • 1970-01-01
      • 2013-04-26
      • 2018-07-07
      • 2013-12-09
      相关资源
      最近更新 更多