ajax 데이터타입 헷갈린 부분과 jsonobject
$(document).ready(function() {
jQuery.ajax({
type:"GET",
url:"/test",
dataType:"JSON", // 옵션이므로 JSON으로 받을게 아니면 안써도 됨
success : function(data) {
// 통신이 성공적으로 이루어졌을 때 이 함수를 타게 된다.
// TODO
},
complete : function(data) {
// 통신이 실패했어도 완료가 되었을 때 이 함수를 타게 된다.
// TODO
},
error : function(xhr, status, error) {
alert("에러발생");
}
});
});
이 부분에서 dataType 이 json 이면 json 으로 받는 것. 보내는 값이 아니고 받는 값임을 생각.
받을때 오류가 많이 났다.
{ "no1" : <%= 변수 %> , "no2" : <%= 변수 %> }
이런 형식이 될 때, 스크립틀릿에 들어가는 값에 특수문자나 다른값이 들어갈때 에러를 보이는 경우가 생김
그래서
JSONObject obj = new JSONObject();
obj.put("calno", calno);
obj.put("title", title);
obj.put("startdate", date_start);
obj.put("enddate", date_end);
obj.put("url", url);
obj.put("color", color);
obj.put("id", id);
response.getWriter().print(obj);
이처럼 jsonObject 로 만들어주는 게 사용하기 좋았음.
jsonobject 참고 사항 - http://aljjabaegi.tistory.com/40