JavaScript AJAX 요청에서 POST 데이터를 전송할 때 필요한 헤더는?
JavaScript AJAX 요청에서 POST 데이터를 전송할 때 필요한 헤더는?
const xhttp = new XMLHttpRequest();
xhttp.open("POST", "process.php");
xhttp.setRequestHeader("Content-type", "___");
xhttp.send("username=john&password=secret");
정답: C
폼 형태의 데이터를 POST로 전송할 때는
application/x-www-form-urlencoded
헤더를 사용합니다.⦁ Content-Type 헤더의 역할:
⦁ 서버에게 전송되는 데이터의 형식을 알려줌
⦁ 서버가 데이터를 올바르게 파싱할 수 있도록 도움
⦁ 주요 Content-Type들:
⦁
application/x-www-form-urlencoded
: 일반 폼 데이터 (키=값&키=값 형식)⦁
application/json
: JSON 형식 데이터⦁
multipart/form-data
: 파일 업로드 시 사용⦁
text/html
: HTML 문서⦁ AJAX POST 요청의 완전한 구조:
xhttp.open("POST", "process.php");
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("username=john&password=secret");
💡 학습 팁
이 문제를 포함한 PHP 과목의 모든 문제를 순차적으로 풀어보세요. 진행상황이 자동으로 저장되어 언제든지 이어서 학습할 수 있습니다.