Possible Duplicate:
Call PHP function from jQuery?
Jquery on button click call php function
$('.refresh').click(
    function(){
       <?php hello(); ?> 
    }
)
PHP Code
<?php
function hello()
{
echo "bye bye"
}
?>
I Want to call a php function from jquery on button click how can i do this ?
From jQuery you can only call php script with this function. Like that:
$.ajax({
   url: 'hello.php',
   success: function (response) {//response is value returned from php (for your example it's "bye bye"
     alert(response);
   }
});
hello.php
<?php
    echo "bye bye"
?>
                        your JS
$('.refresh').click(
    function(){
       $.ajax({
          url: "ajax.php&f=hello",
          type: "GET"
          success: function(data){
              //Do something here with the "data"
          }
       });
    }
)
your ajax.php
<?php
$validFunctions = array("hello","anotherF");
$functName = $_REQUEST['f'];
if(in_array($functName,$validFunctions))
{
    $$functName();
}else{
    echo "You don't have permission to call that function so back off!";
    exit();
}
function hello()
{
    echo "bye bye";
}
function anotherF()
{
    echo "the other funct";
}
function noTouch()
{
    echo "can't touch this!";
}
?>
this is a little example of really basic and pretty ugly RMI type invocation of php methods via ajax
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With