Sorry, I know this question is easy, but I don’t know how to get the response data
from a returned dictionary:
This is my jQuery.get() method:
$("#selectDireccion").change(function() {
$("select option:selected").each(function() {
if ($(this).index() != 0) {
valorKeyId = $(this).val()
$.get("/ajaxRequest?opcion=obtenerSedeKeyId", {
keyId: valorKeyId
}, function(data) {
alert(data)
});
}
});
});
This is what the alert prints:
{"name": "First Value", "phone": "434534"}
How should I do to get the value from the ‘name’ key of the dictionary?
Doing data.name inside an alert has no effect.
Thanks!
It appears you are returning a JSON string. If that is the case, then you first need to run jQuery’s parseJSON function:
Or, better yet (per the comment by @calvin L), use the jQuery getJSON to begin with: