I have two php files one is index.php and other is phpscriptname.php. i need to call differet functions by using ajax and case method. i found a solution in a website which i give below, but this is not working.
index.php as below
<script>
$.ajax({ url: 'phpscriptname.php',
data: {function2call: 'getEmployeesList'},
type: 'post',
success: function(output) {
alert(output);
}
});
</script>
phpscriptname.php as below
<?php?
if(isset($_POST['function2call']) && !empty($_POST['function2call'])) {
$function2call = $_POST['function2call'];
switch($function2call) {
case 'getEmployeesList' : getEmployeesList();break;
}
}
function getEmployeesList(){
return "hai";
}
?>
i was expected "hai" in a popup. but it is not working.
echoinstead ofreturnto get value inajax. so just replacereturn "hai";byecho "hai";Or if you want to return multiple data then refer stackoverflow.com/a/52404102/6309457