You have to use ajax call as described manner--
On javascript side on save.php page-
$.ajax({
type:"POST",
data:'demodata',
url:"save.php?action=php_function", // place your php function name here
dataType: "html",
success:function(response){
alert(response); // It will alert value returned by php function
},
failure:function(response){
alert("there is an error.");
},
});
On PHP side on save.php page-
<?php
if(function_exists($_GET['action']))
{
$_GET['action']();
}
else
{
echo 'There is some error.';
}
function php_function()
{
// some code
echo "result";
}
?>