Results for ajax : 3

1 - get asynchrone avec retour (avec les promises)
function getHTTP(url) {
    return new Promise(function (resolve, reject) {
        var xhr = new XMLHttpRequest();
        xhr.open("GET", url);
        xhr.onload = function() {
            if (this.status >= 200 && this.status < 300) {
                resolve(xhr.response);
            }
        };
        xhr.open("GET", url);
        xhr.send();
    });
}

getHTTP("https://www.google.fr")
.then(function (response) {
    // On récupère le resultat de la requête dans la varible "response"
    console.log(response)
})
			
2 - sendForm - poster un formulaire via ajax (sans lib)
	function sendForm(form){  
    	data='';
		url=form.getAttribute('action');
		Array.prototype.forEach.call(form.elements,function(obj){
			type=obj.getAttribute('type');
			if (
				type!='checkbox'&&type!='radio'&&type!='submit'
				||obj.checked==1
			){
				data+=obj.getAttribute('name')+'='+obj.value+'&';
			}
		});
    	
    	request = new XMLHttpRequest;
		request.open('post', url, true);
		request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		request.send(data);

		// Gestion de la réponse du serveur
		request.onreadystatechange=function(){
			if (request.readyState!=4 && request.status!=200){
				console.log(request.responseText);
			}
		}
	    return false;        
	}
			
3 - poster des données en asynchrone sans jquery
		function post(){
			obj=document.getElementById('message');
			data=obj.value;
			request = new XMLHttpRequest;
			request.open('POST', 'index.php', true);
			
			request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
			request.send("message="+data+"&pseudo=roger");// ici on met name=valeur
			obj.value='';
		}