var debtsOfUser = []; function getConnectedUser(){ var url = '/api/connectedUser/'; $.getJSON(url,function(d){ $("#usrCo").html(d.username); }); } function getDebtsOfUser(){ var url = "/api/debts/"; var html =""; $.getJSON(url,function(d){ $.each(d,function(index,item){ html+=""; html+=""+item.creditor.username+""; html+=""+item.sommeDette+""; html+=""; }); $("#dettes").html(html); }); } function getCreancesOfUser(){ var url = "/api/creances/"; var html =""; $.getJSON(url,function(d){ $.each(d,function(index,item){ html+=""; html+=""+item.borrower.username+""; html+=""+item.sommeDette+""; html+='\n\ \n\ '; html+=""; }); $("#creances").html(html); }); } function deleteDebt(id){ var url = "/api/deleteDette/"; $.ajax({ url:url + $.param({"id":id}), type:"DELETE", success: function(d){ getCreancesOfUser(); } }); } function updateDebtOfUser(){ var url ="/api/addDette/"; var user = $("#username").val(); var dette = $("#sommeDette").val(); var requestData = { 'username':user, 'sommeDette':dette }; $.ajax({ url:url, method:"POST", data:requestData, async:false }).done(function(d){ console.log(d); }).success(function(d){ console.log(d); }).fail(function(d){ alert("Erreur"); }); } (function(){ 'use strict'; getConnectedUser(); getDebtsOfUser(); getCreancesOfUser(); })();