Java에서는 toString()이란 메소드를 사용하여 한 객체의 데이터들을 확인한다.
JavaScript에서는 어떨까? 좀 어려워 보이지만 다음과 같다.
JSON.stringify(Obj);
이를테면, Ajax통신에서 err를 출력할 때 다음과 같이 사용할 수 있다.
$.ajax({
type : 'post',
url : '<%=request.getContextPath()%>/changeProfilePhoto.do',
processData : false,
cache : false,
contentType : false,
data : formData,
dataType : 'json',
success : function(result) {
alert("사진 변경 완료!");
},
error : function(err){
alert("사진 변경 실패:\n"+JSON.stringify(err));
}
});
Node.js에서 클라이언트나 DB로부터 받아온 Object가 제대로 되었는 지 확인할 때 자주 쓰이게 된다.
'Computer > Node.js' 카테고리의 다른 글
JavaScript Libraries. (0) | 2018.07.30 |
---|---|
[Node.js] Object를 JSON.stringify() 깔끔하게 보려면? (0) | 2018.07.30 |