【发布时间】:2013-12-15 16:46:06
【问题描述】:
Firebug 中的 Ajax POST response:
{"key_one": "val_1", "key_2": "val_2", "key_3": ["array_val_1", "array_val_2", "array_val_3"]}
如何使用 jQuery 遍历 key_3 中的数组项?
【问题讨论】:
Firebug 中的 Ajax POST response:
{"key_one": "val_1", "key_2": "val_2", "key_3": ["array_val_1", "array_val_2", "array_val_3"]}
如何使用 jQuery 遍历 key_3 中的数组项?
【问题讨论】:
实际上,我在尝试解决这个问题时得到了这个工作,这就是我使用的:
<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>
【讨论】: