抱歉,这是重复的here https://stackoverflow.com/questions/733314/jquery-loop-over-json-result-from-ajax-success问过,但我对此很陌生,所以我想知道该怎么做?
这是我的 ajax 调用:
$("#btnprocess").click(function () {
$.ajax({
type: "POST",
url: "Default.aspx/GetFilenames",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert(response.d[0]);
alert(response.d[1]);
}
});
});
就个人而言,我能够得到响应,但我需要循环它们。
谁能告诉我我该怎么做?
Use $.each()
.
$.each(response.d, function(key, value) {
//For example
console.log(key + value)
})
Look here http://api.jquery.com/jQuery.each/了解它。 (EDIT: Or here http://tutsplus.com/lesson/each-and-templating/- 如果您愿意的话,这是一个视频教程。)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)