'Ajax responseText parsing to undefined
I'm trying to read a return body of a POST ajax call. It's returning an object "message" with a pair value regarding its price.
For some reason when I try to retrieve the "message"'s value I get undefined. I have tried a few methods including JSON.parse.
I don't want to simply string.replace out the content from the raw string as that would be a messy and ineffective solution.
In this specific example I am trying to retrieve "Please deposit: 1.50"
My function:
.always(function(returnBody){
console.log("raw: " + returnBody.responseText);
var parsed = JSON.parse(returnBody.responseText);
var item = parsed[0];
console.log("stringified: " + JSON.stringify(item));
My log content:
raw: {"message":"Please deposit: 1.50"}
stringified: undefined
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
