-1

How do I call my functions from functions.php to html.php with the use of AJAX? I want to declare my functions inside my html.php file without using include or require. only ajax pls. Thanks allot! see below

functions.php

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

html.php

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

1 Answers1

0

add the below code in html.php

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

and add below code in functions.php

function samplefunc() {
    echo 'Answer';
}

if ($_POST['call_function'] == "samplefunc") {
    samplefunc();
}
Ashish Raj
  • 488
  • 9
  • 22