簡體   English   中英

將數據從ajax錯誤響應存儲到變量

[英]Storing data from ajax error response to variable

我正在嘗試從我的 ajax 錯誤響應中獲取消息值。

在我的 python 代碼中,我正在發送這個。

return JsonResponse({'message':'Online payment of this invoice not supported.'}, status=401)

在我的 ajax 響應的錯誤部分中,如果我使用 console.log(error),我會看到以下響應詳細信息。

{readyState: 4, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …}
abort: ƒ ( statusText )
always: ƒ ()
complete: ƒ ()
done: ƒ ()
error: ƒ ()
fail: ƒ ()
getAllResponseHeaders: ƒ ()
getResponseHeader: ƒ ( key )
overrideMimeType: ƒ ( type )
pipe: ƒ ( /* fnDone, fnFail, fnProgress */ )
progress: ƒ ()
promise: ƒ ( obj )
readyState: 4
responseJSON: {message: "Please ensure that this invoice is eligible for payment."}
responseText: "{"message": "Please ensure that this invoice is eligible for payment."}"
setRequestHeader: ƒ ( name, value )
state: ƒ ()
status: 401
statusCode: ƒ ( map )
statusText: "Unauthorized"
success: ƒ ()
then: ƒ ( /* fnDone, fnFail, fnProgress */ )
__proto__: Object

在我的 javascript 中,如何將我的消息從 responseJSON 存儲到變量? 換句話說,我想將以下字符串存儲在一個變量中:請確保此發票符合付款條件。

謝謝!

        var responseJSON = error.responseJSON;
        var message = responseJSON['message'];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM