본문 바로가기
목차
Spring (boot) 오류 해결

json parse error unrecognized token

by 지각생 2022. 2. 11.
728x90
function btn_deleteCategory() {
  var deleteCategoryNoArray = [];
  $("input[name=deleteCategory]:checked").each(function () {
    deleteCategoryNoArray.push($(this).attr("value"));
  });

  console.log(deleteCategoryNoArray);
  $.ajax({
    type: "POST",
    url: "/category/deleteCategoryName",
    data: JSON.stringify(deleteCategoryNoArray),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
  })
    .done(function (resp) {
      alert("삭제가 완료되었습니다.");
      location.href = "/";
    })
    .fail(function (error) {
      alert(JSON.stringify(error));
    });
}

11번째 라인에 'JSON.stringify'라는 구문

JSON.stringify는 JSON 객체를 String 객체로 변환 시켜주기 때문에 Controller에서 에러 없이 받아주게 된다.

 

 

 

https://dev-yujji.tistory.com/3

 

[Error] ajax 사용 중 'JSON parse error: ~'

ajax로 이것저것 해보던 중 에러를 만났다. JSON parse error: Unrecognized token 'param1': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false'); nested exception is com..

dev-yujji.tistory.com

 

728x90

댓글