웹 개발/🌐 JavaScript
ajax에서 contentType과 dataType의 차이
이재원
2023. 7. 6. 15:03
$.ajax({
type: 'POST',
url: '링크',
data: JSON.stringify(Data),
contentType:"application/json", //클라->서버
dataType:"json",// 서버->클라
success: function(res) {
console.log(res)
},
error : function(xhr,status,error) {
//오류 발생 시 처리
},
complete:function(data,textStatus) {
//작업 완료 후 처리
}
});
}
contentType 은 서버로 전송할때 보낼 데이터의 타입을 지정
dataType : 서버로부터 받을 데이터의 타입을 지정
반응형