반응형
JSON을 사용하여 XmlHttpRequest POST 작성
바닐라 JS를 사용하여 JSON 데이터를 전송하는 AJAX POST 요청을 작성하려면 어떻게 해야 합니까?
content-type은 url 형식으로 인코딩되어 있어 네스트된 JSON을 지원하지 않습니다.
플레인 구 JS에서 네스트된 JSON을 사용하여 POST 요청을 할 수 있는 방법이 있습니까?SO에서 제공되는 다양한 직렬화 방법을 시도했지만 모두 JSON을 하나의 형식으로 만듭니다.
여기 JSON이 있습니다.
{
email: "hello@user.com",
response: {
name: "Tester"
}
}
JSON을 올바르게 사용하면 문제 없이 중첩된 개체를 가질 수 있습니다.
var xmlhttp = new XMLHttpRequest(); // new HttpRequest instance
var theUrl = "/json-handler";
xmlhttp.open("POST", theUrl);
xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xmlhttp.send(JSON.stringify({ "email": "hello@user.com", "response": { "name": "Tester" } }));
언급URL : https://stackoverflow.com/questions/39519246/make-xmlhttprequest-post-using-json
반응형
'bestsource' 카테고리의 다른 글
리액트 라우터 v4와 이점 비교 (0) | 2023.03.15 |
---|---|
스프링 데이터 R2DBC에 쿼리 매개 변수의 값을 기록하시겠습니까? (0) | 2023.03.15 |
JSON 데이터의 동적 형식(다른 유형) (0) | 2023.03.10 |
React로 구축된 입력 요소를 프로그래밍 방식으로 채우려면 어떻게 해야 합니까? (0) | 2023.03.10 |
제목 직후에 커스텀 투고 유형 편집 화면에 버튼/링크 추가 (0) | 2023.03.10 |