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",
data:{"id":$("#txt").val()},
dataType:"json",
cache:false,
success:function(data){
var str="";
str+="ID:"+data.member.id+"<br>";
str+="PW:"+data.member.pw+"<br>";
str+="ADDR:"+data.member.addr+"<br>";
str+="TEL:"+data.member.tel+"<br>";
$("#con").html(str);
}
});
});
});
</script>
<body>
<input type="text" id="txt">
<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"%>
<%@ page import="java.util.*" %>
<%@ page import="kr.co.seoulit.member.dao.*" %>
<%@ page import="kr.co.seoulit.member.to.*" %>
<%@ page import="net.sf.json.*"%>
<%
String id=request.getParameter("id");
MemberDAO dao=MemberDAOImpl.getInstance();
MemberBean member=dao.selectMember(id);
HashMap<String,Object> map=new HashMap<String,Object>();
map.put("member",member);
JSONObject jsonObject= new JSONObject();
jsonObject.putAll(map);
out.println(jsonObject);
%>
'개발하자 > ajax&json' 카테고리의 다른 글
id값 리스트로 만들기 (0) | 2015.03.03 |
---|---|
dataType:'json',$.getJSON,$.parseJSON (0) | 2015.03.03 |
db에 member테이블 정보이용하여 id,pw,addr,tel출력하기 (0) | 2015.03.03 |
id,pw,addr,tel출력하기 (json) (0) | 2015.03.03 |
json2 error (0) | 2015.03.03 |