如何使用AJAX将函数从functions.php调用到html.php?我想在不使用include或require的情况下在html.php文件中声明我的函数。只有ajax请。谢谢分配!见下文
的functions.php
<?php
function samplefunc(){
echo "Hello world";
}
?>
html.php
<html>
<body>
<?php samplefunc(); ?>
</body>
</html>
答案 0 :(得分:0)
在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();
}