forked from benkeen/generatedata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ajax.php
executable file
·43 lines (40 loc) · 1.39 KB
/
ajax.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
<?php
/**
* This handles all Ajax requests for the Data Generator Core. Note that we only include the library.php
* here, we don't Core::init(). Depending on the context (e.g. installation), that may not be desired.
*/
require_once(__DIR__ . "/library.php");
// sessions needed here AFTER installation, to get access to $user [or should it be passed &
// validated with all requests?]
header("Cache-Control: private, no-cache, must-revalidate");
header("Content-Type: application/json; charset=utf-8");
$ajaxRequest = new AjaxRequest(@$_POST["action"], $_POST);
$encoded = json_encode($ajaxRequest->getResponse());
$errorCode = json_last_error();
if ($errorCode) {
switch ($errorCode) {
case JSON_ERROR_NONE:
echo ' - No errors';
break;
case JSON_ERROR_DEPTH:
echo ' - Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
echo ' - Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
echo ' - Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
echo ' - Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
echo ' - Unknown error';
break;
}
} else {
echo $encoded;
}