I'm encountering an error response within the ajax error function;
$.ajax(Request).error(function (Response) {
var content = JSON.stringify(Response.responseText);
var obj = JSON.parse(content);
console.log("Response.responseText:",Response.responseText);
console.log("Response.responseText.Message:", Response.responseText.Message);
console.log("Response.responseText[Message]:", Response.responseText["Message"]);
console.log("content:", content);
console.log("content.Message:", content.Message);
console.log("content[Message]:", content["Message"]);
console.log("obj:", obj);
console.log("obj.message:", obj.Message);
console.log("obj[Message]:", obj["Message"]);
});
The results from console.log are shown here : https://i.sstatic.net/4g00N.jpg
I am trying to retrieve Message but have not been successful in accessing its value. How can I access Message?
Main Question
- why are all of them showing as undefined?
- How can I access Message?
Solution
var parsed= JSON.parse(startpaymentResponse.responseText);
console.log("parsed:", parsed);
console.log("parsed.Message:", parsed.Message);
console.log("parsed[Message]:", parsed["Message"]);
In the meantime, when I paste Response.responseText into JSON Deserialize Online, everything works correctly.
Response.responseText: {"Message":"The request is invalid.","ModelState":{"model.Amount":["The field Amount must be a string or array type with a minimum length of '4'."],"model.TotalAmount":["The field TotalAmount must be a string or array type with a minimum length of '4'."]}}