是否可以使用ajax加载单个php函数


Is it possible to use ajax to load a single php function?

示例:我写了一个php脚本,如下所示:

<?PHP 
    function _hello(){  "Hello world!"; }
    function _bye(){  "Good Bye!"; }
    function _night(){  "Good Night!"; }
?>
<html>
    <head>!-- required files -- </head>  
    <body>
        <div id="thisDIV">
            <? echo _hello(); ?>
        </div>
        <div>
            This is another Division.
        </div>
    </body>
</html>

有没有可能我只是想使用javascript重新加载除法(id=thisDIV)中的函数_hello()?或者ajax、Jquery ajax或其他什么。。我该怎么做?谢谢

您可以在URL中添加一个查询字符串,然后将其与您想要运行的函数绑定:

例如:http://myurl.com/page.php?function=hello

在page.php中:

$function = $_GET['function'];
if($function == "hello") {
    hello();
}

等等