-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>
2
  • refer this link stackoverflow.com/questions/4152431/… Commented Mar 24, 2015 at 5:40
  • There are a lot tutorials available in internet. Please do a Google before asking here. Commented Mar 24, 2015 at 5:41

1 Answer 1

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();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.