function httpGet(theUrl) { var xmlHttp = null; xmlHttp = new XMLHttpRequest(); xmlHttp.open( "GET", theUrl, false ); xmlHttp.send( null ); return xmlHttp.responseText; } var working = false; $('.login').on('submit', function(e) { e.preventDefault(); if (working) return; working = true; var $this = $(this), $state = $this.find('button > .state'); $this.addClass('loading'); url = "process/login?username=" + document.getElementById('username').value + "&password=" + document.getElementById('password').value; result = httpGet(url); $state.html('Mencoba masuk..'); setTimeout(function() { if (result=="success") { //Success $this.addClass('ok'); $state.html('Selamat datang ' + document.getElementById('username').value + '!'); setTimeout(function() { $state.html('Memproses...'); $this.removeClass('ok loading'); working = false; $this.removeClass('loading'); window.location = "https://cdr.alvandipalar.com/"; }, 2500); } else { //FAIL $this.addClass('fail'); $state.html('Username atau Password salah! '); setTimeout(function() { $state.html('Masuk'); $this.removeClass('fail loading'); working = false; $this.removeClass('loading'); }, 2500); } }, 1500); });