$.ajax({
url: 'http://localhost:8080/chat/receive',
type: 'POST',
data: data,
// 수정부분
contentType: false,
processData: false,
success: function (res) {
console.log("Success!!");
},
});
Ajax로 데이터를 넘겨줄 때 Uncaught TypeError : Illegal invocation 에러가 발생했는데, 이는 알맞은 데이터 타입이 와야
하는데, 다른 데이터 타입이 들어와서 나는 오류이다.
위와 같이 contentType, processData의 옵션을 false로 주면 해결된다.
기본적으로 보통 JSON 데이터를 받으려면 contentType: application/json; charset-utf-8 으로 줄텐데,
이를 false로 줌으로써 multipart/form-data를 받을 수 있다.
processData도 false를 주면 DOMDocument 또는 기타 처리되지 않은 파일 데이터들을 받을 수 있다.
jQuery 내부적으로 query string 형태로 만드는 기능을 비활성화하기 때문.
'개발 > Frontend' 카테고리의 다른 글
[HTML] button을 눌러도 submit이 안될 때 (0) | 2023.07.29 |
---|---|
[리액트네이티브] React-Native UI Template (0) | 2023.04.21 |
[리액트네이티브] React Native 주석 처리 방법 (0) | 2023.04.21 |
[Flutter] onPageChanged 에러 (No named parameter with the name 'onPageChanged') 해결 방법 (0) | 2022.08.22 |
[Flutter] Flutter null safety 비활성화 ( can't have a value of 'null' because of its type but the implicit default value is 'null' 에러 해결) (0) | 2022.08.22 |
댓글