0

How to add jQuery function in PHP function File?

Example :

<script type="text/javascript" src="assets/js/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/jquery.livequery.js"></script>
<script type="text/javascript" src="assets/js/jquery.timeago.js"></script>
<?php
class db{
public $db;

function get_news()
{
bla bla
}
}

When run the code, the jQuery is not working. Please help.

Thank you

4
  • Where is the jquery code? Here you just load two JS files Commented Jul 26, 2014 at 8:04
  • Sorry, just updated the code. That include jQuery.min.js but still cant working Commented Jul 26, 2014 at 8:06
  • Its only a jquery file you include. After that you should execute Jquery function inside script tag Commented Jul 26, 2014 at 8:10
  • @hiDayurie Please read this post Commented Jul 26, 2014 at 8:16

3 Answers 3

1

You can't run jQuery function in PHP. You can run them from HTML. First close php:

?>
<script>
    function get_news() { blabla; }
</script>
<?php

If this is not what you're looking for then there is no way for you to do what you're looking for.

Sign up to request clarification or add additional context in comments.

Comments

0

This is a sample code,

<script type="text/javascript" src="assets/js/jquery.min.js"></script>

<script type="text/javascript">
    $(document).ready(function() {
      alert("Test");
     });
</script>

<?php
   echo "PHP code here";
?>

Comments

0

You can Echo jQuery function call to run it

<?php
echo "<script type=\"text/javascript\">
$(document).ready(function() {
  alert(\"Test\");
 });
</script>";
?>

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.