XMLHttpRequest 객체 _
XMLHttpRequest 객체를 사용하면 전체 페이지를 다시 로드하지 않고도 웹 페이지의 일부를 업데이트할 수 있습니다.
직접 해보십시오 - 예
간단한 XMLHttpRequest를 만들고 TXT 파일에서 데이터를 검색합니다.
헤더 정보를 검색합니다. 리소스(파일)의 헤더 정보를 검색합니다.
검색합니다. 리소스(파일)의 특정 헤더 정보를 검색합니다.
사용자가 입력 필드에 문자를 입력하는 동안 웹 페이지가 웹 서버와 통신하는 방법.
웹 페이지가 XMLHttpRequest 개체를 사용하여 데이터베이스에서 정보를 가져오는 방법.
검색 XMLHttpRequest를 만들어 XML 파일에서 데이터를 검색하고 HTML 테이블에 데이터를 표시합니다.
XMLHttpRequest 객체
XMLHttpRequest 객체는 배후에서 서버와 데이터를 교환하는 데 사용됩니다.
XMLHttpRequest 객체는 개발자의 꿈 입니다 .
- 페이지를 새로고침하지 않고 웹페이지 업데이트
- 페이지가 로드된 후 서버에서 데이터 요청
- 페이지가 로드된 후 서버에서 데이터 수신
- 백그라운드에서 서버로 데이터 보내기
XMLHttpRequest 객체 메소드
Method | Description |
---|---|
abort() | Cancels the current request |
getAllResponseHeaders() | Returns header information |
getResponseHeader() | Returns specific header information |
open(method,url,async,uname,pswd) | Specifies the type of request, the URL, if the request should be handled asynchronously or not, and other optional attributes of a request
method: the type of request: GET or POST url: the location of the file on the server async: true (asynchronous) or false (synchronous) |
send(string) | send(string) Sends the request off to the server. string: Only used for POST requests |
setRequestHeader() | Adds a label/value pair to the header to be sent |
XMLHttpRequest 객체 속성
Property | Description |
---|---|
onreadystatechange | Stores a function (or the name of a function) to be called automatically each time the readyState property changes |
readyState | Holds the status of the XMLHttpRequest. Changes from 0 to 4: 0: request not initialized 1: server connection established 2: request received 3: processing request 4: request finished and response is ready |
responseText | Returns the response data as a string |
responseXML | Returns the response data as XML data |
status | Returns the status-number (e.g. "404" for "Not Found" or "200" for "OK") |
statusText | Returns the status-text (e.g. "Not Found" or "OK") |