IT Study/오류 발견
ajax - json parse error
hhyyyjun
2022. 12. 23. 16:30
ajax 데이터 처리도중 다음과 같은 오류가 발생하였다.
json parse error: unrecognized token 'service': was expecting (json string, number, array, object or token 'null', 'true' or 'false'); nested exception
ajax와 전달할 데이터 params

원인 : 전달할 데이터(params)를 문자열화하지 않았기 때문에 Controller에서 데이터를 받을 때 문제가 생기는 것이다.

해결방법은 JSON.stringify를 추가하는 것이다.
JSON.stringify 는 json 데이터를 string 객체로 변환시켜주기 때문에 Controller에서 문제없이 받을 수 있다.
참고하면 좋을듯하다.
https://stackoverflow.com/questions/2845459/jquery-how-to-make-post-use-contenttype-application-json