JQuery .each() 메서드
http://api.jquery.com/jquery.each/
jQuery.each( array, callback )
- arrayType: ArrayThe array to iterate over.
- callbackThe function that will be executed on every object.
version added: 1.0jQuery.each( object, callback )
- objectType: ObjectThe object to iterate over.
- callbackThe function that will be executed on every object.
Examples:
Example: Iterates through the array displaying each number as both a word and numeral
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
$("#listBnt").click(function viewAjax() {
$('#jsonlist').empty();
console.log("리스트 버튼 들어옴");
$.ajax({
type: "GET",
url: "/testajax/main/users/",
dataType: "json",
success: function (response) {
console.log("불러오기 성공");
// each 함수 $(불러온데이터).each(fucntion (인덱스, 불러온데이터각각의 값)){}
$(response).each(function (i,data ) {
var d = "<table class='table table-striped'>";
d += "<th class='tid'>" + data.id + "</th>";
d += "<th class='tname'>" + data.name + "</th>";
d += "<th class='temail'>" + data.email + "</th>";
d += "<th class='tage'>" + data.age + "</th>";
d += "</table>";
$("#jsonlist").append(d);
})
},
error: function (e) {
console.log("error");
console.log("error 정보 : " + e.status);
}
});
});
'Programming > jQuery' 카테고리의 다른 글
[jquery] 패스워드 에러 표현 innerHtml (0) | 2017.03.27 |
---|---|
[ajax]multipart form 전송 (0) | 2016.10.13 |
[jQuery] function 정의 (0) | 2015.07.02 |