亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 HTTP 403 響應中獲取自定義錯誤響應文本

如何在 HTTP 403 響應中獲取自定義錯誤響應文本

智慧大石 2021-10-14 15:46:45
我使用以下方法發出 AJAX 請求:function getJSON(url, callback) {    var xhr = new XMLHttpRequest();    xhr.open("GET", url, true);    xhr.responseType = "json";    xhr.onload = function() {        if (xhr.status === 200) {            callback(null, xhr.response);        }         else {            /*var errorObj = { status: xhr.status, statusText: xhr.statusText };            callback(errorObj, xhr.response);*/            callback(xhr.status, xhr.response);        }    };    xhr.send();};如果狀態為 403.xhr.response為空,我必須從服務器獲取自定義響應文本,盡管我可以在 Chromium 調試器窗口的網絡選項卡中看到自定義錯誤消息。如何訪問自定義響應文本?
查看完整描述

2 回答

?
不負相思意

TA貢獻1777條經驗 獲得超10個贊

嘗試這個 :


  if (xhr.status === 200) {

            callback(null, xhr.response);

        } else if(xhr.status === 403){

            callback(xhr.status, "not found =(");

         }

        else {

            /*var errorObj = { status: xhr.status, statusText: xhr.statusText };

            callback(errorObj, xhr.response);*/

            callback(xhr.status, xhr.response);

        }


查看完整回答
反對 回復 2021-10-14
?
largeQ

TA貢獻2039條經驗 獲得超8個贊

xhr.responseText 應該是訣竅


查看完整回答
反對 回復 2021-10-14
  • 2 回答
  • 0 關注
  • 262 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號