I have a $.POST call that return the name of a function that need to be ran but it wont execute the function and I don't know why.
Here is an example:
JS file:
$(function(){
$.post('test.php',{event: 'add'},
function(data){
data.func(data.msg);
},'json');
function test(msg){
alert(msg);
}
});
PHP Ajax:
<?php
switch($_POST['event']){
case 'add':
$output['func'] = 'test';
$output['msg'] = 'This is add message';
break;
case 'delete':
$output['func'] = 'test';
$output['msg'] = 'This is delete message';
break;
}
echo json_encode($output);
?>
The problem I am having is the ajax is returning the name of the function (test) but it will not run the function, how do I fix this?