var debtsOfUser = []; 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+='\n\ \n\ '; html+=""; }); $("#dettes").html(html); }); } function deleteDebt(id){ var url = "/api/deleteDette/"; $.ajax({ url:url + $.param({"id":id}), type:"DELETE", success: function(d){ getDebtsOfUser(); } }); } 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("Succes"); console.log(d); }).fail(function(d){ alert("Erreur"); console.log("Fail"); console.log(d); }); } (function(){ 'use strict'; getDebtsOfUser(); })();