$(document).ready(function(){ $("#lb").on("click",function(event){ event.preventDefault(); $.ajax({ url: BASE_URL + 'user/ext_login', method: "POST", data: $("#myForm").serialize() + "&checkLogin=true", success: function(response){ response = JSON.parse(response); if(response.pesan == ''){ localStorage.setItem('access_token', response.authorization); window.location = BASE_URL + 'user/index'; }else{ $("#pesan").text(response.pesan); } }, error: function(xhr, status, error) { console.error("An error occurred: " + status + "\nError: " + error); $("#pesan").text("Terjadi kesalahan pada server. Silakan coba lagi nanti."); } }); return false; // prevent form submitting }); });