Вы можете определить класс в php для обработки таких вещей, как:
functions.php:
class MyFunctions {
function foo() {
// code here
// if you need to pass in some parameters, you can do it via jQuery and fetch the data like so (for the jQuery, see below)
if($_GET['name'] == "john") { } // do stuff
}
function bar() {
// code here
}
static function handleFn($fName) {
if(method_exists(__CLASS__, $fname)) {
echo $this->{$fname}(); die; // since AJAX, just echo the output and stop executing
}
}
}
if(!empty($_GET['f'])) {
MyFunctions::handleFn($_GET['f']);
}
Затем выполните ваш вызов ajax следующим образом (при условии, что jQuery):
$.get("/functions.php?f=func_name_to_call", {name: "John", hobby: "Programming"}, function(data) {
});