El objeto XMLHttpRequest
Con el objeto XMLHttpRequest puede actualizar partes de una página web, sin recargar toda la página.
Pruébelo usted mismo - Ejemplos
Cree un XMLHttpRequest simple y recupere datos de un archivo TXT.
Recuperar información de encabezado de un recurso (archivo).
Recuperar información de encabezado específica de un recurso (archivo).
Cómo una página web puede comunicarse con un servidor web mientras un usuario escribe caracteres en un campo de entrada.
Cómo una página web puede obtener información de una base de datos con el objeto XMLHttpRequest.
Cree una XMLHttpRequest para recuperar datos de un archivo XML y mostrar los datos en una tabla HTML.
El objeto XMLHttpRequest
El objeto XMLHttpRequest se utiliza para intercambiar datos con un servidor en segundo plano.
El objeto XMLHttpRequest es el sueño de los desarrolladores , porque puedes:
- Actualizar una página web sin recargar la página
- Solicitar datos de un servidor después de que se haya cargado la página
- Recibir datos de un servidor después de que se haya cargado la página
- Enviar datos a un servidor en segundo plano
Métodos de objeto 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 |
Propiedades del objeto 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") |