2
js is along with html
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form id="form">
<input type="text" name="login" id="login">
<input type="pass" name="senha" id="senha">
<input type="submit" name="btn" id="btn" value="Enviar" >
</form>
<h1 id="erro"></h1>
<script>
var form = document.querySelector("#form");
var btn = document.querySelector("#btn");
var erro = document.querySelector("#erro");
form.addEventListener("click", function(e){
e.preventDefault();
if(btn.value == "enviando"){
return;
}
btn.value = "enviando";
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200){
erro.innerHTML = this.responseText;
}
};
xhttp.open("GET", "registrar.php", true);
xhttp.send();
});
</script>
</body>
</html>