Ajax response improves

This commit is contained in:
Diego Najar 2019-01-31 20:07:59 +01:00
parent 79095de5ca
commit ec7e0aaf4c
6 changed files with 15 additions and 43 deletions

View File

@ -7,9 +7,8 @@ $oldKey = isset($_POST['currentKey']) ? $_POST['currentKey'] : '';
$slug = $pages->generateKey($text, $parent, $returnSlug=true, $oldKey); $slug = $pages->generateKey($text, $parent, $returnSlug=true, $oldKey);
exit (json_encode(array( ajaxResponse(0, 'Slug generated.', array(
'status'=>0,
'slug'=>$slug 'slug'=>$slug
))); ));
?> ?>

View File

@ -7,10 +7,7 @@ header('Content-Type: application/json');
$query = isset($_GET['query']) ? Text::lowercase($_GET['query']) : false; $query = isset($_GET['query']) ? Text::lowercase($_GET['query']) : false;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
if ($query===false) { if ($query===false) {
exit (json_encode(array( ajaxResponse(1, 'Invalid query.');
'status'=>1,
'files'=>'Invalid query.'
)));
} }
$tmp = array(); $tmp = array();

View File

@ -7,10 +7,7 @@ header('Content-Type: application/json');
$query = isset($_GET['query']) ? Text::lowercase($_GET['query']) : false; $query = isset($_GET['query']) ? Text::lowercase($_GET['query']) : false;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
if ($query===false) { if ($query===false) {
exit (json_encode(array( ajaxResponse(1, 'Invalid query.');
'status'=>1,
'files'=>'Invalid query.'
)));
} }
$tmp = array(); $tmp = array();

View File

@ -13,18 +13,12 @@ $uuid = isset($_POST['uuid']) ? $_POST['uuid'] : false;
// Check UUID // Check UUID
if (empty($uuid)) { if (empty($uuid)) {
exit (json_encode(array( ajaxResponse(1, 'Autosave fail. UUID not defined.');
'status'=>1,
'message'=>'Autosave fail. UUID not defined.'
)));
} }
// Check content length to create the autosave page // Check content length to create the autosave page
if (Text::length($content)<100) { if (Text::length($content)<100) {
exit (json_encode(array( ajaxResponse(1, 'Autosave not completed. The content length is less than 100 characters.');
'status'=>1,
'message'=>'Autosave not completed. The content length is less than 100 characters.'
)));
} }
$autosaveUUID = 'autosave-'.$uuid; $autosaveUUID = 'autosave-'.$uuid;
@ -47,10 +41,8 @@ if (empty($pageKey)) {
editPage($page); editPage($page);
} }
exit (json_encode(array( ajaxResponse(0, 'Autosave successfully.', array(
'status'=>0,
'message'=>'Autosave successfully.',
'uuid'=>$autosaveUUID 'uuid'=>$autosaveUUID
))); ));
?> ?>

View File

@ -2,10 +2,7 @@
header('Content-Type: application/json'); header('Content-Type: application/json');
if (!isset($_FILES['inputFile'])) { if (!isset($_FILES['inputFile'])) {
exit (json_encode(array( ajaxResponse(1, 'Error trying to upload the site logo.');
'status'=>1,
'message'=>'Error trying to upload the site logo.'
)));
} }
// File extension // File extension
@ -32,12 +29,10 @@ chmod(PATH_UPLOADS.$filename, 0644);
// Store the filename in the database // Store the filename in the database
$site->set(array('logo'=>$filename)); $site->set(array('logo'=>$filename));
exit (json_encode(array( ajaxResponse(0, 'Image uploaded.', array(
'status'=>0,
'message'=>'Image uploaded success.',
'filename'=>$filename, 'filename'=>$filename,
'absoluteURL'=>DOMAIN_UPLOADS.$filename, 'absoluteURL'=>DOMAIN_UPLOADS.$filename,
'absolutePath'=>PATH_UPLOADS.$filename 'absolutePath'=>PATH_UPLOADS.$filename
))); ));
?> ?>

View File

@ -8,17 +8,11 @@ $username = empty($_POST['username']) ? false : $_POST['username'];
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
if ($username===false) { if ($username===false) {
exit (json_encode(array( ajaxResponse(1, 'Error in username.');
'status'=>1,
'message'=>'Error in username.'
)));
} }
if (!isset($_FILES['profilePictureInputFile'])) { if (!isset($_FILES['profilePictureInputFile'])) {
exit (json_encode(array( ajaxResponse(1, 'Error trying to upload the profile picture.');
'status'=>1,
'message'=>'Error trying to upload the profile picture.'
)));
} }
// File extension // File extension
@ -42,12 +36,10 @@ unlink(PATH_TMP.$tmpFilename);
// Permissions // Permissions
chmod(PATH_UPLOADS_PROFILES.$filename, 0644); chmod(PATH_UPLOADS_PROFILES.$filename, 0644);
exit (json_encode(array( ajaxResponse(0, 'Image uploaded.', array(
'status'=>0,
'message'=>'Image uploaded success.',
'filename'=>$filename, 'filename'=>$filename,
'absoluteURL'=>DOMAIN_UPLOADS_PROFILES.$filename, 'absoluteURL'=>DOMAIN_UPLOADS_PROFILES.$filename,
'absolutePath'=>PATH_UPLOADS_PROFILES.$filename 'absolutePath'=>PATH_UPLOADS_PROFILES.$filename
))); ));
?> ?>