Tout sur XMLHttpRequest dans JavaScript | par Javascript Jeep🚙💨 | Meilleure programmation | Octobre 2020

Online Coding Courses for Kids

1. Créez un objet XMLHttpRequest

let request = new XMLHttpRequest();

2. Configurez l’objet avec les dĂ©tails de la demande

request.open(method, URL, [async, user, password])

3. Envoyer la demande

request.send();
xhr.onerror = function() {     console.log(`Unable to make request`); };
let url = "https://medium.com/search?q=javascriptjeep";let request = new XMLHttpRequest();request.open("GET", url);request.onload = function(){
console.log(request.response);
}
request.send();
xhr.timeout = 10000; //time in milliseconds , actually 10s 
let url = new URL('https://medium.com/search');url.searchParams.set('q', 'JavaScript Jeep');request.open('GET', url);request.send();request.onload = function(){
console.log(request.response);
}
1. text → get as string2. arraybuffer → get as ArrayBuffer3. blob → get as Blob4. document → get as XML document5. json → get as JSON
let url = "https://medium.com/search?q=javascriptjeep";let request = new XMLHttpRequest();request.open("GET", url);request.onload = function(){
console.log(request.response);
}
request.responseType = "document";request.send();

Close Menu