Created
October 5, 2017 16:14
-
-
Save Sanix-Darker/31311b28e735f601d0b217c45b01218d to your computer and use it in GitHub Desktop.
[JS] XmlhttpRequest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function onProgress(event) { | |
| if (event.lengthComputable) { | |
| var percentComplete = (event.loaded / event.total)*100; | |
| console.log("Envoi en cours: %d%%", percentComplete); | |
| } else { | |
| // Impossible de calculer la progression puisque la taille totale est inconnue | |
| } | |
| } | |
| function onError(event) { | |
| console.error("Une erreur " + event.target.status + " s'est produite au cours de la réception du document."); | |
| } | |
| function onLoad(event) { | |
| // Ici, this.readyState égale XMLHttpRequest.DONE . | |
| if (this.status === 200) { | |
| console.log("Réponse reçu: %s", this.responseText); | |
| //================== C'EST ICI QUE TU PEUX GERER AVEC TON WAY DE ALERT OU FAIRE TON ACTION =============== | |
| } else { | |
| console.log("Status de la réponse: %d (%s)", this.status, this.statusText); | |
| } | |
| } | |
| function onLoadEnd(event) { | |
| // Cet événement est exécuté, une fois la requête terminée. | |
| console.log("Le transfert est terminé. (peut importe le résultat)"); | |
| //-----------------------------------------OU AUSSI ICI ------------------------------------------------- | |
| //================== C'EST ICI QUE TU PEUX GERER AVEC TON WAY DE ALERT OU FAIRE TON ACTION =============== | |
| //-----------------------------------------OU AUSSI ICI ------------------------------------------------- | |
| } | |
| var request = new XMLHttpRequest(); | |
| var formData = new FormData(); | |
| formData.append("example", $('#example').val()); | |
| // Tous ces call back vont appeller les methodes declarees en haut | |
| request.onprogress = onProgress; | |
| request.onerror = onError; | |
| request.onload = onLoad; | |
| request.onloadend = onLoadEnd; | |
| req.open('POST', 'http://www.ddark.com', true); | |
| req.send(formData); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TY Sanix bro !!!