서버와 상호작용하기 위해 XMLHttpRequest(XHR) 객체를 사용합니다. 전체 페이지의 새로고침없이도 URL 로부터 데이터를 받아올 수 있습니다. 이는 웹 페이지가 사용자가 하고 있는 것을 방해하지 않으면서 페이지의 일부를 업데이트할 수 있도록 해줍니다. XMLHttpRequest 는 AJAX 프로그래밍에 주로 사용됩니다.

XMLHttpRequest 는 그 이름으로봐서 XML 만 받아올 수 있을 것 같아 보이지만, 모든 종류의 데이터를 받아오는데 사용할 수 있습니다. 또한 HTTP 이외의 프로토콜도 지원합니다(file 과 ftp 포함).

통신을 통해 서버로부터 이벤트나 메시지 데이터를 받아야 한다면, EventSource 를 통한 server-sent events 사용을 고려하세요. 완전 양방향 통신을 해야 한다면 웹 소켓이 더 나은 선택일 수 있습니다.

생성자

XMLHttpRequest()
생성자는 XMLHttpRequest 를 초기화합니다. 다른 모든 메소드 호출이전에 호출되어야 합니다.

속성

이 인터페이스는 XMLHttpRequestEventTargetEventTarget 의 속성도 상속합니다.

XMLHttpRequest.onreadystatechange
readyState 어트리뷰트가 변경될때마다 호출되는 EventHandler 입니다.
XMLHttpRequest.readyState Read only
요청의 상태를 unsigned short 로 반환합니다.
XMLHttpRequest.response Read only
응답 엔티티 바디를 갖는하는 XMLHttpRequest.responseType 의 값에 따라 ArrayBuffer, Blob, Document, JavaScript 객체, 또는 DOMString 을 반환합니다.
XMLHttpRequest.responseText Read only
요청에 대한 응답을 텍스트로 갖는 DOMString 을 반환합니다. 요청이 성공하지 못했거나 아직 전송되지 않았을 경우 null 을 반환합니다.
XMLHttpRequest.responseType
응답 타입을 정의하는 열거형 값입니다.
XMLHttpRequest.responseURL Read only
응답의 연속된 URL 을 반환합니다. URL 이 null 인 경우 빈 문자열을 반환합니다.
XMLHttpRequest.responseXML Read only
요청에 대한 응답을 갖는 Document 를 반환합니다. 요청이 성공하지 못했거나, 아직 전송되지 않았거나, XML 또는 HTML 로 파싱할 수 없는 경우 null 을 반환합니다. workers 에서는 사용이 불가합니다.
XMLHttpRequest.status Read only
요청의 응답 상태를 갖는 unsigned short 를 반환합니다.
XMLHttpRequest.statusText Read only
HTTP 서버에 의해 반환된 응답 문자열을 갖는 DOMString 을 반환합니다. XMLHTTPRequest.status 와는 다르게, 응답 메시지의 전체 텍스트를 갖습니다(예, "200 OK").

노트: HTTP/2 명세(8.1.2.4 Response Pseudo-Header Fields)에 따르면, HTTP/2 는 HTTP/1.1 상태 라인에 포함된 버전이나 원인 문구를 전달하는 방법을 정의하지 않습니다.

XMLHttpRequest.timeout
요청이 자동으로 종료될때까지 걸린 시간을 밀리초 단위로 나타내는 unsigned long 입니다.
XMLHttpRequestEventTarget.ontimeout
요청 시간 초과때마다 호출되는 EventHandler 입니다.
XMLHttpRequest.upload Read only
업로드 과정을 나타내는 XMLHttpRequestUpload 입니다.
XMLHttpRequest.withCredentials
사이트 간 Access-Control 요청이 쿠키나 인증 헤더와 같은 자격 증명을 사용해야하는지 여부를 나타내는 Boolean 입니다.

비표준 속성

XMLHttpRequest.channelRead only
nsIChannel 입니다. 요청을 수행할 때 객체에 의해 사용된 채널입니다.
XMLHttpRequest.mozAnonRead only
Boolean 입니다. true 일 경우, 요청이 쿠키나 인증 헤더 없이 전송됩니다.
XMLHttpRequest.mozSystemRead only
Boolean 입니다. true 일 경우, 요청에대해 동일 출처 정책(same origin policy)이 강제되지 않습니다.
XMLHttpRequest.mozBackgroundRequest
 Boolean 입니다. 객체가 백그라운드 서비스 요청을 나타내는지 여부를 표시합니다.
XMLHttpRequest.mozResponseArrayBuffer 안씀 Gecko 6 Read only
ArrayBuffer. 요청에 대한 응답입니다. 타입이 지정된 JavaScript 배열입니다.
XMLHttpRequest.multipart안씀 Gecko 22
This Gecko-only feature, a boolean, was removed in Firefox/Gecko 22.
대신 Server-Sent Events, 웹 소켓, 또는 프로그레스 이벤트의 responseText 를 사용하시기 바랍니다.

이벤트 핸들러

XMLHttpRequest 인스턴스의 속성으로써 onreadystatechange 는 모든 브라우저에서 지원됩니다.

그 이후, 많은 부가적인 이벤트 핸들러가 다양한 브라우저에서 구현되었습니다(onloadonerroronprogress, 등등.). XMLHttpRequest 사용하기 글을 확인하세요.

Firefox 를 포함해, 더 최신 브라우저는 on* 속성을 핸들러 함수로 설정하는것 뿐만 아니라 표준 addEventListener() API 를 통해 XMLHttpRequest 이벤트 리스닝도 지원합니다.

메소드

XMLHttpRequest.abort()
이미 전송된 요청을 중지합니다.
XMLHttpRequest.getAllResponseHeaders()
모든 응답 헤더를 CRLF 로 구분한 문자열로 반환합니다. 응답을 받지 않은 경우 null 입니다.
XMLHttpRequest.getResponseHeader()
지정한 헤더의 텍스트를 갖는 문자열을 반환합니다. 응답을 아직 받지 못했거나 응답에 헤더가 존재하지 않을 경우 null 입니다.
XMLHttpRequest.open()
요청을 초기화합니다. 이 메소드는 네이티브 코드로부터의 요청을 초기화하기 위해 JavaScript 코드에 의해 사용됩니다. 대신 openRequest() 를 사용하세요.
XMLHttpRequest.overrideMimeType()
서버에의해 반환된 MIME 타입을 오버라이드합니다.
XMLHttpRequest.send()
요청을 보냅니다. 요청이 비동기인 경우(기본값), 이 메소드는 요청이 보내진 즉시 반환합니다.
XMLHttpRequest.setRequestHeader()
HTTP 요청 헤더의 값을 설정합니다. open() 후, send() 전에 setRequestHeader() 를 호출해야합니다.

비표준 메소드

XMLHttpRequest.init()
C++ 코드에서 사용할 객체를 초기화합니다.

주의: 이 메소드는 JavaScript 에서 호출되면 안됩니다.

XMLHttpRequest.openRequest()
요청을 초기화합니다. 이 메소드는 JavaScript 코부로부터의 요청을 초기화하기위해 네이티브 코드에서 사용됩니다. 대신 open() 을 사용하세요. open() 에 대한 문서를 확인하세요.
XMLHttpRequest.sendAsBinary()
바이너리 데이터를 보내는 send() 메소드의 다른 방식입니다.

명세

명세 상태 코멘트
XMLHttpRequest Living Standard Live standard, latest version

브라우저 호환성

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support 1Edge Full support YesFirefox Full support 1IE Full support 7Opera Full support YesSafari Full support 1.2WebView Android Full support YesChrome Android Full support 18Edge Mobile Full support 12Firefox Android Full support 4Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
onreadystatechangeChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 7
Notes
Full support 7
Notes
Notes Internet Explorer version 5 and 6 supported ajax calls using ActiveXObject()
Opera Full support YesSafari Full support 1.2WebView Android Full support 1Chrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
readyStateChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 7Opera Full support YesSafari Full support 1.2WebView Android Full support YesChrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
responseChrome Full support YesEdge Full support 12Firefox Full support YesIE ? Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
responseTextChrome Full support YesEdge Full support 12Firefox Full support YesIE ?
Notes
?
Notes
Notes Before IE 10, the value of XMLHttpRequest.responseText could be read only once the request was complete.
Opera Full support YesSafari Full support 10WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
responseTypeChrome Full support 31Edge Full support 12Firefox Full support 6IE Full support 10Opera Full support 18Safari Full support 7WebView Android Full support 55Chrome Android Full support 55Edge Mobile Full support YesFirefox Android Full support 50Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support 6.0
responseURLChrome Full support 37Edge Full support 14Firefox Full support 32IE No support NoOpera Full support 24Safari Full support 8WebView Android Full support 37Chrome Android Full support 37Edge Mobile ? Firefox Android Full support 32Opera Android Full support 24Safari iOS ? Samsung Internet Android Full support Yes
responseXMLChrome Full support YesEdge Full support 12Firefox Full support Yes
Notes
Full support Yes
Notes
Notes Prior to Firefox 51, an error parsing the received data added a <parsererror> node to the top of the Document and then returned the Document in whatever state it happens to be in. This was inconsistent with the specification. Starting with Firefox 51, this scenario now correctly returns null as per the spec.
IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support Yes
Notes
Full support Yes
Notes
Notes Prior to Firefox 51, an error parsing the received data added a <parsererror> node to the top of the Document and then returned the Document in whatever state it happens to be in. This was inconsistent with the specification. Starting with Firefox 51, this scenario now correctly returns null as per the spec.
Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
statusChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 7
Notes
Full support 7
Notes
Notes Internet Explorer version 5 and 6 supported ajax calls using ActiveXObject()
Opera Full support YesSafari Full support 1.2WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
statusTextChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 7
Notes
Full support 7
Notes
Notes Internet Explorer version 5 and 6 supported ajax calls using ActiveXObject()
Opera Full support YesSafari Full support 1.2WebView Android Full support YesChrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
timeoutChrome Full support 29Edge Full support 12Firefox Full support 12IE Full support 8Opera Full support 17
Full support 17
No support 12 — 16
Safari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
uploadChrome Full support 1Edge Full support 12Firefox Full support YesIE ? Opera Full support YesSafari Full support 10WebView Android Full support YesChrome Android Full support 18Edge Mobile ? Firefox Android ? Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
withCredentialsChrome Full support YesEdge Full support 12Firefox Full support 3.5
Notes
Full support 3.5
Notes
Notes Starting with Firefox 11, it's no longer supported to use the withCredentials attribute when performing synchronous requests. Attempting to do so throws an NS_ERROR_DOM_INVALID_ACCESS_ERR exception.
IE Full support 10
Notes
Full support 10
Notes
Notes Internet Explorer versions 8 and 9 supported cross-domain requests (CORS) using XDomainRequest
Opera Full support 12Safari Full support 4WebView Android Full support YesChrome Android Full support YesEdge Mobile ? Firefox Android Full support 4
Notes
Full support 4
Notes
Notes Starting with Firefox 11, it's no longer supported to use the withCredentials attribute when performing synchronous requests. Attempting to do so throws an NS_ERROR_DOM_INVALID_ACCESS_ERR exception.
Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
abortChrome Full support 18Edge Full support 12Firefox Full support YesIE Full support 7
Full support 7
Full support 5
Notes
Notes Implemented via ActiveXObject
Opera Full support YesSafari Full support 1.2WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
getAllResponseHeadersChrome Full support 1Edge Full support 12Firefox Full support 4
Notes
Full support 4
Notes
Notes Starting from Firefox 49, empty headers are returned as empty strings in case the preference network.http.keep_empty_response_headers_as_empty_string is set to true, defaulting to false. Before Firefox 49 empty headers had been ignored. Since Firefox 50 the preference defaults to true.
IE Full support 7
Full support 7
Full support 5
Notes
Notes Implemented via ActiveXObject
Opera Full support YesSafari Full support 1.2WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4
Notes
Full support 4
Notes
Notes Starting from Firefox 49, empty headers are returned as empty strings in case the preference network.http.keep_empty_response_headers_as_empty_string is set to true, defaulting to false. Before Firefox 49 empty headers had been ignored. Since Firefox 50 the preference defaults to true.
Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
getResponseHeaderChrome Full support 1Edge Full support 12Firefox Full support Yes
Notes
Full support Yes
Notes
Notes Starting from Firefox 49, empty headers are returned as empty strings in case the preference network.http.keep_empty_response_headers_as_empty_string is set to true, defaulting to false. Before Firefox 49 empty headers had been ignored. Since Firefox 50 the preference defaults to true.
IE Full support 7
Full support 7
Full support 5
Notes
Notes Implemented via ActiveXObject
Opera Full support YesSafari Full support 1.2WebView Android Full support YesChrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support Yes
Notes
Full support Yes
Notes
Notes Starting from Firefox 49, empty headers are returned as empty strings in case the preference network.http.keep_empty_response_headers_as_empty_string is set to true, defaulting to false. Before Firefox 49 empty headers had been ignored. Since Firefox 50 the preference defaults to true.
Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes
openChrome Full support 1Edge Full support 12Firefox Full support Yes
Notes
Full support Yes
Notes
Notes Starting in Firefox 30, synchronous requests on the main thread have been deprecated due to their negative impact on performance and the user experience. Therefore, the async parameter may not be false except in a Worker.
IE Full support 7
Full support 7
Full support 5
Notes
Notes Implemented via ActiveXObject
Opera Full support YesSafari Full support 1.2WebView Android Full support YesChrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support Yes
Notes
Full support Yes
Notes
Notes Starting in Firefox 30, synchronous requests on the main thread have been deprecated due to their negative impact on performance and the user experience. Therefore, the async parameter may not be false except in a Worker.
Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
overrideMimeTypeChrome Full support 1Edge Full support 12Firefox Full support YesIE Full support 11
Full support 11
Full support 5
Notes
Notes Implemented via ActiveXObject
Opera Full support YesSafari Full support 1.2WebView Android Full support YesChrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
sendChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 7
Full support 7
Full support 5
Notes
Notes Implemented via ActiveXObject
Opera Full support YesSafari Full support 1.2WebView Android Full support YesChrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
sendAsBinary
DeprecatedNon-standard
Chrome No support No
Notes
No support No
Notes
Notes There is a polyfill available to support sendAsBinary().
Edge No support NoFirefox No support 2 — 31IE No support NoOpera No support NoSafari No support NoWebView Android No support No
Notes
No support No
Notes
Notes There is a polyfill available to support sendAsBinary().
Chrome Android No support No
Notes
No support No
Notes
Notes There is a polyfill available to support sendAsBinary().
Edge Mobile No support NoFirefox Android No support 4 — 31Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support No
setRequestHeaderChrome Full support 1Edge Full support 12Firefox Full support YesIE Full support 7
Full support 7
Full support 5
Notes
Notes Implemented via ActiveXObject
Opera Full support YesSafari Full support 1.2WebView Android Full support YesChrome Android Full support 18Edge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.

함께 보기

 

문서 태그 및 공헌자

이 페이지의 공헌자: cs09g, MyungGyu, silmari, Suguni, Wafe, Sebuls
최종 변경자: cs09g,