제이쿼리(jQuery) js 신텍스
$('#<id>').on()
- Attach an event handler function for one or more events to the selected elements.
$('#<id>').val()
- Get the current value of the first element in the set of matched elements.
$.ajax()
- Perform an asynchronous HTTP (Ajax) request.
- Controller의 API를 부를 때 사용한다.
data: JSON.stringify(<data>)
- Convert a JavaScript object into a string. The result will be a string following the JSON notation.
- Controller에서 이 data를 받을 때의 형식은 JSON 노테이션을 따른 스트링 형태이다. Spring automatically deserializes the JSON into a Java type, assuming an appropriate one is specified. (스프링 @Requestbody의 특성) 따라서 이름끼리의 매핑만 잘 된다면, 원하는 값이 들어간 객체가 자동으로 만들어진다.
- 결론은 JSON.stringify(json문자열)로 넘어온 파라미터는 서버에서 @RequestBody를 이용하면 받을 수 있다.
window.location.href = '/'
- 메인페이지로 이동한다. (ex. 글 등록이 성공하면 처음 페이지로 돌아간다.)