I’ve read multiple articles and questions on this, but none of the suggestions seem to be working for me. I have a json result that my ajax call returns, and I want to put each value of the result into input fields. I’m getting close, "JSON.stringify(data)" is returning my full result in my input field.. But how do I get just the "recovery" value from it?
Here’s what the full data result looks like:
{"data":{ "id":12, "name":"hello", "addDt":"2020-11-06T00:00:00", "recovery":"hello", "latestRecovery":"hello", "latestSituation":"hello", "nextSteps":"hello", "requestId":null}}
And here’s my current ajax call:
function LoadUpdate(id) { $ .ajax({ url: "?handler=updateValuesJson&id=" + id, type: "GET", dataType: "json", async: false, success: function (data) { document.getElementById("recovery").innerHTML = JSON.stringify(data); // I need "recovery" element from this string result $ ("#updatemodal").modal(); } }); }
What I’ve tried out:
- JSON.stringify(data) is the full string result (but I need the value of "recovery")
- JSON.stringify(data.recovery) is "undefined"
- JSON.stringify(data[3]) is "undefined"
- data is "[object Object]"
- data.recovery is "undefined"
- data["recovery"] is "undefined"
- JSON.parse(data)[i][‘recovery’] isn’t successful
I’m brand new to ajax/json – What am I not understanding here?