This is my sample JSON response:
[{"id":11137,"name":"Agra"},{"id":11138,"name":"Albizzate"}]
and i need to iterate each array object and print id
and name
:
$.ajax({
url: '{{ path('ajax_provinces') }}',
type: 'POST',
dataType: 'json',
data: {region_id: this.value},
success: function(provinces) {},
error: function() { alert("error"); },
complete: function(provinces) {
$('select#regions ~ span > img').fadeOut('slow');
$.each(provinces, function(key, val) {
alert(key + ": " + val);
});
}
});
The problem is i'm gettig strange results: function names, function bodies and other internal stuff from jQuery. It seems like it's iterating through jQuery library functions! Any clue what's going on?