【问题标题】:declaring/calling php function from another file using ajax使用ajax从另一个文件声明/调用php函数
【发布时间】:2015-05-27 08:27:18
【问题描述】:

如何使用 AJAX 将我的函数从 functions.php 调用到 html.php?我想在我的 html.php 文件中声明我的函数,而不使用 include 或 require。只有ajax请。感谢分配!见下文

functions.php

<?php
function samplefunc(){ 
   echo "Hello world"; 
}
?>

html.php

<html>
<body>
<?php samplefunc(); ?>
</body>
</html>

【问题讨论】:

标签: php ajax function


【解决方案1】:

在 html.php 中添加以下代码

$.post("functions.php", {call_function: samplefunc})
                .done(function(response) {
alert(response);
}

并在functions.php中添加以下代码

function samplefunc() {
    echo 'Answer';
}

if ($_POST['call_function'] == "samplefunc") {
    samplefunc();
}

【讨论】:

    猜你喜欢
    • 2013-12-17
    • 2021-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-26
    • 2017-03-17
    相关资源
    最近更新 更多