response
Ajax POST в Firebug:
{"key_one": "val_1", "key_2": "val_2", "key_3": ["array_val_1", "array_val_2", "array_val_3"]}
Как перебирать элементы массива в key_3
с помощью jQuery?
Фактически, я получил эту работу, пытаясь понять это, это то, что я использовал:
<script>
$(document).on("submit", "#my_div", function(e) {
e.preventDefault();
$.ajax({
type: 'POST',
url: '/my_path',
data: $(this).serialize(),
dataType: 'json',
success: function(results) {
if (something) {
//do this
} else {
// do this
$("#content_area").html("");
$("#content_area").append(results.key_2);
// and for each item in the array, do something with each item in the array
my_array = results.key_3;
$.each(my_array, function(k, v) {
alert(v) // this will alert each value in the array
});
}
}
});
});
</script>