idempotentes
sûres
GET / HTTP/1.1[CRLF]
Host: www.cff.ch[CRLF]
Connection: close[CRLF]
User-Agent: Opera/9.20 (Windows NT 6.0; U; en)[CRLF]
Accept-Encoding: gzip[CRLF]
Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7[CRLF]
Cache-Control: no[CRLF]
Accept-Language: de,en;q=0.7,en-us;q=0.3[CRLF]
Referer: http://web-sniffer.net/[CRLF]
[CRLF]
HTTP Status Code: HTTP/1.1 302 Found
Date: Mon, 16 Nov 2009 08:01:35 GMT
Server: Apache
Location: http://www.sbb.ch/fr/
Content-Length: 205
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head><title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="http://www.sbb.ch/fr/">here</a>.</p>
</body></html>
var xhr;
function createXMLHttpRequest()
{
if (window.ActiveXObject)
{
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest)
{
xhr = new XMLHttpRequest();
}
}
<!DOCTYPE html>
<html>
<head>
<script src="jquery.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").load("demo_test.txt");
});
});
</script>
</head>
<body>
<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
<button>Get External Content</button>
</body>
</html>
readyState, status, onreadystatechange
responseText, responseXML
open (Verbe, URI, async) :
Verbe
HTTP : “GET”, “POST” ou “PUT”URI
: destinataire de la requêteasync
(bool) : true
= asynchrone,
false
= bloquantsend (null | string)
: peut être bloquantesetRequestHeader(header, value)
getResponseHeader(string)
abort()
readystate == 4
status == 200
responseText
responseXML
getElementsByTagName(), ...
)<?xml version="1.0" ?>
<liste>
<personne>
<nom>Berger</nom>
<prenom>Laurent</prenom>
</personne>
<personne>
<nom>Borgo</nom>
<prenom>Sébastien</prenom>
</personne>
<personne>
<nom>Bux</nom>
<prenom>Rémy</prenom>
</personne>
</liste>
responseXML
[
{"nom": "Berger", "prénom": "Laurent"},
{"nom": "Borgo", "prénom": "Sébastien"},
{"nom": "Bux", "prénom": "Rémy"}
]
eval()
: évalue et exécute la chaîne en paramètrefetch("fichier.json")
.then(function(response) {
return response.json()
})
.then(function(json) {
console.log(json);
})
.catch(function(error) {
console.error("erreur", error)
})