1$.ajax({
2 url: "www.site.com/page",
3 success: function(data){
4 $('#data').text(data);
5 },
6 error: function(){
7 alert("There was an error.");
8 }
9 });
1
2let xhr = new XMLHttpRequest();
3
4xhr.open("GET", "une/url");
5
6xhr.responseType = "json";
7
8xhr.send();
9
10xhr.onload = function(){
11 if (xhr.status != 200){
12 alert("Erreur " + xhr.status + " : " + xhr.statusText);
13 }else{
14 alert(xhr.response.length + " octets téléchargés\n" + JSON.stringify(xhr.response));
15 }
16};
17
18xhr.onerror = function(){
19 alert("La requête a échoué");
20};
21
22xhr.onprogress = function(event){
23 if (event.lengthComputable){
24 alert(event.loaded + " octets reçus sur un total de " + event.total);
25 }
26};
1const xhttp = new XMLHttpRequest();
2xhttp.onload = function() {
3 document.getElementById("demo").innerHTML = this.responseText;
4}
5xhttp.open("GET", URL);
6xhttp.send();