【发布时间】:2022-01-11 20:56:08
【问题描述】:
我目前有以下代码,需要获取location 参数以重定向到。如何使用 statusCode 设置来获取它?
Ajax 调用
$.ajax({
url: url,
data: (def.data ? (def.convertToJson ? JSON.stringify(def.data) : def.data) : ''),
type: def.type,
dataType: def.dataType,
cache: def.cache,
contentType: def.contentType,
statusCode: {
401: function (response) {
debugger
window.location = GET LOCATION URL FROM RESPONSE
}}
响应参数
response.getAllResponseHeaders()
'access-control-allow-headers: Origin, X-Requested-With, Content-Type, 接受\r\n访问控制允许来源:*\r\n缓存控制: 私有\r\n内容长度:58\r\n内容类型:文本/html\r\n日期:星期一, 格林威治标准时间 2021 年 12 月 6 日 16:51:23\r\n位置: https://localhost:44360/store?storeorganizationid=24917#/login?returnurl=https%3a%2f%2flocalhost%3a44360%2fstore%2faccount%3fstoreorganizationid%3d24917%26_%3d1638809474810\r\n服务器: Microsoft-IIS/10.0\r\nx-aspnet-版本: 4.0.30319\r\nx-aspnetmvc-version: 5.2\r\nx-exposure-server: EastUS2\r\nx-exposure-sport: 篮球\r\nx-powered-by: ASP.NET\r\nx-源文件: =?UTF-8?B?RjpcTXkgV2Vic1xCYXNrZXRiYWxsVG91cm5hbWVudHNcTmV3UmVnaXN0cmF0aW9uXFdlYnNpdGVzXFRvdXJuYW1lbnRzXHN0b3JlXGFjY291bnQ=?=\r\nx-ua 兼容: IE=Edge,chrome=1\r\n'
【问题讨论】:
标签: javascript jquery ajax http-status-codes http-status-code-401