function getUserWalletBalance(callbackFunction) { $.ajax({ url: '/my/balance', type: 'GET', dataType: 'json', // Assuming the server responds with JSON success: function(response) { // The 'response' should contain the wallet balance // Invoke the callback function with the wallet balance if (typeof callbackFunction === 'function') { callbackFunction(response.data); } }, error: function(xhr, status, error) { // Handle error scenario console.error("Error fetching wallet balance:", status, error); // Optionally, invoke the callback with an error or null } }); } function updateBalanceonPage(balance) { if (balance.gem !== undefined){ $('.gemCount').text(balance.gem); $('.gemCount').addClass('fade').addClass('show'); $('.heartsLeft').text(balance.heart); } }