25 lines
506 B
Markdown
25 lines
506 B
Markdown
|
# .cadoles-slide-title[API du DOM (5/5)]
|
||
|
|
||
|
**XMLHttpRequest**
|
||
|
```js
|
||
|
// Soit une URl /data.json
|
||
|
|
||
|
var req = new XMLHttpRequest();
|
||
|
|
||
|
// Arguments: méthode HTTP, URL, asynchrone ou non
|
||
|
req.open('GET', '/data.json', true);
|
||
|
|
||
|
req.onreadystatechange = function (evt) {
|
||
|
if (req.readyState === 4) {
|
||
|
if(req.status === 200) {
|
||
|
console.log(req.responseText);
|
||
|
} else {
|
||
|
console.log("Erreur pendant le chargement de la page.");
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// Arguments: corps de la requête HTTP
|
||
|
req.send(null);
|
||
|
```
|