Hello! I'm new to JavaScript and I have a question regarding AJAX requests. I've successfully received a JSON response and I want to dynamically append specific data from this response to HTML fields.
Below is an example of the JSON response that I obtained from Chrome Inspector:
Object {message: Object}
message
:
Object
created_at
:
"2017-06-16 23:12:33"
data
:
"{"subject":"New Message","message":"Admin sent a new message"}"
id
:
"d93e8aa4-c56f-4312-9d2a-f7609a67acdf"
notifiable_id
:
1
notifiable_type
:
"App\Models\Doctor"
read_at
:
null
type
:
"App\Notifications\AdminMessage"
updated_at
:
"2017-06-16 23:12:33"
__proto__
:
Object
__proto__
:
Object
I've managed to append the 'created at' field to my HTML using the following code snippet:
success:function(result){
console.log(result);
$("#msg_date").html(result.message.created_at);
$("#msg_content").html();
}
However, I'm struggling to access and display the 'subject' and 'message' fields from the 'data' object within the JSON response.
$("#msg_content").html(result.message.data);
When I try the above code, I get the entire 'data' object displayed but I'm unsure of how to extract and display the individual fields.