when the page loads, it fires a PHP function, from the functions.php
file, to grab data from the DB and populate a DOM element, like so:
<h1>TOTALS: <?php fetchTotals(); ?></h1>
after submitting data, via JS-handled form, i want to fire that PHP function again to update the totals and not repeat code.
i have read this and this to see if there was anything useful there. and i already know i can just use $.ajax
or $.post
to run a file, but since the function already exists, and i hate repeating code, i wanted to know if there's a more elegant solution that obviates creating a file that exactly duplicates an already-extant function. follow me here? DRY, good; duplicate, bad.
Again: looking for more elegant way, not a basic how-to.
if not, then that's just the beast and screw DRY. but i want to be better. :)