본문 바로가기

개발하자/ajax&json

id,pw,addr,tel출력하기 (json)

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>

$(document).ready(function(){

$("#b").click(function(){
 $.ajax({
 url:"a.jsp",
 dataType:"json",
 cache:false,
 success:function(data){
 var str="";
 str+="ID:"+data.id;
 str+="PW:"+data.pw;
 str+="ADDR:"+data.addr;
 str+="TEL:"+data.tel;

 $("#con").html(str);
 }
 });
});

});
</script>
<body>
<input type="button" id="b" value="회원정보보기">
<div id="con"></div>
</body>
</html>

 

a.jsp

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

<%@ page language="java" contentType="text/html; charset=EUC-KR"
 pageEncoding="EUC-KR"%>
{"addr":"aa","id":"bb","pw":"cc","tel":"dd"}