As a complete beginner, I find JavaScript to be quite challenging and struggle with simple tasks.
I have a PHP script that retrieves data from a website using JS. This PHP script updates the database and returns a success message using the following code:
echo json_encode(array('success'=>'true'));
I've created a function that triggers actions when the "success" message is returned:
success: function(){
....
}
Now I want to enhance it further. My PHP script will also return a message that should be displayed in a specific DIV.
The message could be something like:
"error-msg"=>"Could not write to DB." or "success-msg"=>"Data successfully saved in DB."
I'm unsure how to determine if the returned data is an "error-msg" or "success-msg." I don't know how to extract the message string and display it in the designated DIV.
Can anyone provide guidance on this issue?
Thank you!