我目前有以下代碼,需要獲取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, Accept\r\naccess-control-allow-origin: *\r\ncache-control: private\r\ncontent-length: 58 \r\n內容型別:text/html\r\n日期:2021 年 12 月 6 日星期一 16:51:23 GMT\r\n位置:https://localhost:44360/store?storeorganizationid=24917#/login?returnurl= https://localhost:44360/store/account?storeorganizationid=24917&_=1638809474810\r\n服務器:Microsoft-IIS/10.0\r\nx-aspnet-version:4.0.3031版本: 5.2\r\nx-exposure-server: EastUS2\r\nx-exposure-sport: Basketball\r\nx-powered-by: ASP.NET\r\nx-sourcefiles: =?UTF-8?B? RjpcTXkgV2Vic1xCYXNrZXRiYWxsVG91cm5hbWVudHNcTmV3UmVnaXN0cmF0aW9uXFdlYnNpdGVzXFRvdXJuYW1lbnRzXHN0b3JlXGFjY291兼容\rchrome=\uarn=?
uj5u.com熱心網友回復:
這將獲得該值:
response.split('location:')[1].split("\r\n")[0];
let response = 'access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept\r\naccess-control-allow-origin: *\r\ncache-control: private\r\ncontent-length: 58\r\ncontent-type: text/html\r\ndate: Mon, 06 Dec 2021 16:51:23 GMT\r\nlocation: https://localhost:44360/store?storeorganizationid=24917#/login?returnurl=https://localhost:44360/store/account?storeorganizationid=24917&_=1638809474810\r\nserver: Microsoft-IIS/10.0\r\nx-aspnet-version: 4.0.30319\r\nx-aspnetmvc-version: 5.2\r\nx-exposure-server: EastUS2\r\nx-exposure-sport: Basketball\r\nx-powered-by: ASP.NET\r\nx-sourcefiles: =?UTF-8?B?RjpcTXkgV2Vic1xCYXNrZXRiYWxsVG91cm5hbWVudHNcTmV3UmVnaXN0cmF0aW9uXFdlYnNpdGVzXFRvdXJuYW1lbnRzXHN0b3JlXGFjY291bnQ=?=\r\nx-ua-compatible: IE=Edge,chrome=1\r\n'
let loc = response.split('location:')[1].split("\r\n")[0];
console.log(loc);
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/374351.html
標籤:javascript 查询 阿贾克斯 http-状态码 http-status-code-401
上一篇:如何從頭開始播放HTML5視頻?
