본문 바로가기

개발하자/ajax&json

id값 리스트로 만들기

b.jsp

======================================================

 

<%@ page language="java" contentType="text/html; charset=EUC-KR"
 pageEncoding="EUC-KR"%>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$.ajax({
  url:"a.jsp",
  dataType:"json",
  success:function(data){

  var items = [];
  $.each( data.memberlist, function( index, member ) {
  items.push( "<li>" + member.id + "</li>" );
  });

  $( "<ol/>", {
  html: items.join( "" )
  }).appendTo( "body" );

  }
  });
</script>
<body>

</body>
</html>

 

a.jsp

=======================================================

<%@ page language="java" contentType="text/html; charset=EUC-KR"
 pageEncoding="EUC-KR"%>
{
 "memberlist":[
 {"id":"aa","pw":"11"},
 {"id":"bb","pw":"22"},
 {"id":"cc","pw":"33"}
 ]
}