JSFiddle - React, Tailwind, and code Playground
by Salmin Skenderovic
HTML
<form id="myForm" enctype='multipart/form-data'>
<input type="file">
<br>
<br>
<input type="text">
<br>
<br>
<input type="submit">
</form>
JavaScript
var form = document.getElementById("myForm");
form.addEventListener("submit", handleForm);
function handleForm(e){
e.preventDefault();
var xhr = new XMLHttpRequest();
xhr.timeout = 2000;
xhr.onreadystatechange = function(e){
console.log(this);
if (xhr.readyState === 4){
if (xhr.status === 200){
// debugger;
// console.log(xhr.response);
// Callback(xhr.response);
} else {
console.error("XHR didn't work: ", xhr.status);
}
}
}
xhr.ontimeout = function (){
console.error("request timedout: ", xhr);
}
xhr.open("get", "https://api.github.com/users/vintharas/repos", /*async*/ true);
// xhr.responseType = "text";
xhr.send();
}