document.getElementById("logout").addEventListener("click", function(event){ $.ajax({ url: "http://localhost:8080/logout", type:"POST", data: "{}", contentType:"application/json; charset=utf-8", dataType: 'text', success: function(succ){ alert( "Logout successful."); window.location = "/login?logoutSuccessful"; }, error: function(err) { alert(err); } }); });