How to call a PHP function on the click of a button

Button clicks are client side whereas PHP is executed server side, but you can achieve this by using Ajax:

$('.button').click(function() {
  $.ajax({
    type: "POST",
    url: "some.php",
    data: { name: "John" }
  }).done(function( msg ) {
    alert( "Data Saved: " + msg );
  });
});

In your PHP file:

<?php
    function abc($name){
        // Your code here
    }
?>

Leave a Comment