简体   繁体   English

将数据从ajax错误响应存储到变量

[英]Storing data from ajax error response to variable

I'm trying to obtain a message value from my ajax error response.我正在尝试从我的 ajax 错误响应中获取消息值。

within my python code, i'm sending this.在我的 python 代码中,我正在发送这个。

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

Within the error section of my ajax response, if I console.log(error), I see the following response details.在我的 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

Within my javascript, how can I store my message from responseJSON to a variable?在我的 javascript 中,如何将我的消息从 responseJSON 存储到变量? In other words, I want to store the following string in a variable: Please ensure that this invoice is eligible for payment.换句话说,我想将以下字符串存储在一个变量中:请确保此发票符合付款条件。

Thanks!谢谢!

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM