-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserverFile.php
49 lines (37 loc) · 1.05 KB
/
serverFile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
header('Content-type: application/json');
if (isset($_POST['action']) && tokenValid())
{
if (is_callable($_POST['action']))
{
$params = [];
if (isset($_POST['params']))
{
$params = json_decode($_POST['params'],true);
}
call_user_func($_POST['action'],$params);
}
else
{
sendResponse( [] , 0 , ['message'=> 'function '.$_POST['action'].' does not exists']);
}
}
else
{
sendResponse( [] , 0 , ['message'=> 'Missing a valid function name (data-action) ']);
}
function tokenValid()
{
//Token in $_POST['token']
return true;
}
function defaultAction($params)
{
sendResponse(['data'=>$params['param'].' response']);
}
function sendResponse($callBackParams,$status=1,$error = array())
{
//In error you can add specific datas to send to your js. (wrong parameters,..)
$response = ['status'=>$status,'callBackParams'=>$callBackParams,'error'=>$error];
echo json_encode($response);
}