본문 바로가기

개발하자/ajax&json

data에 배열넣어서 json으로 원하는 value값 얻어오기

a.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(){
 var str='{"bb":"cc","dd":"ee"}';

 $.ajax({
 url:"b.jsp",
 data:{"aa":str},
 //dataType:"json",
 cache:false,
 success:function(data){
alert(data);
 }
 });
});

</script>
<body>

</body>
</html>

 

 

 

b.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 str=request.getParameter("aa");

 HashMap<String,Object> map=new HashMap<String,Object>();

 JSONObject jsonObject=JSONObject.fromObject(str);
 String bb=(String)jsonObject.get("bb");
 String dd=(String)jsonObject.get("dd");
 
 out.println(bb+","+dd);
%>