I have a JSON string coming from an ajax call and I want to assign a value to a predefined variable:
var predefined = "hello world";
var foo = {"msg":"predefined"}; // The JSON string
I need to display the standard text by accessing it like this:
alert(foo.msg)
UPDATE: To clarify, here is my AJAX request:
var success_msg = "Your email has been sent successfully!";
$.ajax({
url: "ajax-share-email.php",
type: "POST",
dataType: "json",
data: {},
success: function(data) {
if (data.status == "success") {
msg.text(data.msg).addClass("email-msg-success");
} else {
msg.text(data.msg).addClass("email-msg-error");
}
}
})
The response from ajax-share-email.php is:
{"status":"success", "msg":"success_msg"}