It's clear from reading through threads that I can call a PHP function using Ajax / JQuery, but I can't quite get my head around the particulars.
Let's say I have a function foo() which simply adds 'bar' to some string I pass in. foo() lives in foo.php. To use this in my JavaScript-less HTML, I'd do something like this:
<?php include 'foo.php';?>
<?php echo foo('bar')?>
...and my output is "foobar". Great.
I suspect I do something like so to grab the output of foo() via JavaScript:
<script>
$.post("http://foo.com/foo.php", {
<Magic happens here>
}, function(response) {
useTheOutput(response);
});
</script>
....but I'm not clear on whether I should be POSTing or GETing...and how to pass in a value, like 'bar'.
Can anyone push me in the right direction? Here are other threads that discuss the same thing, I just can't connect all the dots: