$.ajax({
type: "post",
url: "/board/newreply",
data: JSON.stringify({
"postidx" : idx,
"reply" : reply
}),
dataType:'json',
async: true, //비동기 여부
contentType: "application/json",
success: function (result) {
console.log(result);
}
})
컨트롤러
// 댓글 작성
@RequestMapping("/board/newreply")
public ResponseEntity<Map<String, Object>> newReply(@RequestBody HashMap<String,Object> data){
Map<String, Object> map = new HashMap<String, Object>();
String postidx = (String)data.get("postidx");
String reply = (String)data.get("reply");
int result = replyservice.newReply(postidx, reply);
if(result > 0) {
map.put("성공", result);
}else {
map.put("실패", result);
}
return new ResponseEntity<Map<String, Object>>(map, HttpStatus.OK);
}
ajax에서 dataType을 json으로 써줬음에도
POST방식은 JSON.stringify를 써줘야 null이 아닌 올바른 값이 넘어가는 것을 확인했다.
'개발' 카테고리의 다른 글
[에러일기] Path contains invalid character: (0) | 2023.09.19 |
---|---|
CallableStatement로 Stored Procedure 사용하기 (0) | 2023.09.19 |
Mysql : INSERT 후 다른 테이블 UPDATE하는 트리거 (0) | 2023.02.06 |
포스트맨으로 스프링 시큐리티가 적용된 프로젝트 테스트하기 (0) | 2023.02.03 |
스프링 시큐리티 컨트롤러에서 로그인한 customUser 받아오기 (0) | 2023.02.02 |