简体   繁体   中英

Storing data from ajax error response to variable

I'm trying to obtain a message value from my ajax error response.

within my python code, i'm sending this.

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.

{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? 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'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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