【问题标题】:Create See Other response from web api创建查看来自 web api 的其他响应
【发布时间】:2017-09-13 08:59:41
【问题描述】:

我在网站上有一个下载 pdf 的按钮。单击它后,我将点击POST API,它将创建一个潜在客户并在成功时重定向到另一个 url(pdf 位置)。我为此使用SeeOther Http status (303)。

如何从 web api 返回 303 响应? jquery ajax中如何处理?

当前的 API 方法:

Response.Headers.add("Location", pdfUrl);
return StatusCode(HttpStstusCode.SeeOther);

不确定如何处理 ajax 响应,因为它来自 ajax 失败块。

【问题讨论】:

    标签: jquery ajax asp.net-web-api http-status-code-303


    【解决方案1】:

    这是标准行为。如果您检查jQuery source for $.ajax,您会看到当 HTTP 状态代码为时,请求被计为“成功”:

    isSuccess = status >= 200 && status < 300 || status === 304;
    

    这就是为什么您的 303 响应会进入 error 处理程序。您要么需要在那里处理响应,要么使用不同的 HTTP 响应代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-28
      • 2020-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多