Die XMLHttpRequest- objek
Met die XMLHttpRequest-objek kan jy dele van 'n webblad opdateer, sonder om die hele bladsy te herlaai.
Probeer dit self - voorbeelde
Skep 'n eenvoudige XMLHttpRequest, en haal data uit 'n TXT-lêer.
Haal kopinligting van 'n hulpbron (lêer) op.
Haal spesifieke kopinligting van 'n hulpbron (lêer) op.
Hoe 'n webblad met 'n webbediener kan kommunikeer terwyl 'n gebruiker karakters in 'n invoerveld tik.
Hoe 'n webblad inligting van 'n databasis kan haal met die XMLHttpRequest-objek.
op Skep 'n XMLHttpRequest om data van 'n XML-lêer af te haal en die data in 'n HTML-tabel te vertoon.
Die XMLHttpRequest-objek
Die XMLHttpRequest-objek word gebruik om data met 'n bediener agter die skerms uit te ruil.
Die XMLHttpRequest-objek is die ontwikkelaars se droom , want jy kan:
- Dateer 'n webblad op sonder om die bladsy te herlaai
- Versoek data vanaf 'n bediener nadat die bladsy gelaai is
- Ontvang data vanaf 'n bediener nadat die bladsy gelaai is
- Stuur data na 'n bediener in die agtergrond
XMLHttpRequest-objekmetodes
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 Object Properties
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") |