document.getElementById("loginsubmit").addEventListener("click", function () { var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) { alert("logged in"); console.log("dziala"); } else if (this.readyState == 4) { alert("something not work :( " + this.status); console.log("nie dziala"); } } xhttp.open("POST", "https://dragonmaster.pl/inz/user/login"); xhttp.send('{"username":"' + document.getElementById("loginusername").value + '","password":"' + document.getElementById("loginpassword").value + '"}'); }); function submit() { ("form").submit(function () { return false; }) }