diff --git a/Backend/controller/getPost.php b/Backend/controller/getPost.php
index f2cfc87..02080ff 100644
--- a/Backend/controller/getPost.php
+++ b/Backend/controller/getPost.php
@@ -5,7 +5,10 @@ use Backend\Model\Post;
header('Content-Type: application/json;charset=UTF-8');
-$data = Post::all();
+if(isset($_POST['id']))
+ $data = Post::find($_POST['id']);
+else
+ $data = Post::all();
echo $data;
diff --git a/Backend/controller/update.php b/Backend/controller/update.php
index 70f4581..fbd9a48 100644
--- a/Backend/controller/update.php
+++ b/Backend/controller/update.php
@@ -4,14 +4,12 @@ require "../../bootstrap.php";
use Backend\Model\Post;
-if(isset($_POST['update'])){
+if(isset($_POST['id'])){
$post = Post::query()->find($_POST['id']);
$post->title = $_POST['upTitle'];
$post->description = $_POST['upDescription'];
- if(!$post->update()){
- echo "Error could not update";
- }else{
- header("location: ../../Frontend/admin.php");
+ if($post->update()){
+ return 1;
}
}
diff --git a/Backend/controller/upload.php b/Backend/controller/upload.php
index 0fcbd9d..ecd1241 100644
--- a/Backend/controller/upload.php
+++ b/Backend/controller/upload.php
@@ -13,9 +13,6 @@ if(isset($_POST['title'])){
$post->description = $_POST['description'];
//Call the save function.
- if(!$post->save()){
- return http_response_code(400);
- }else{
- echo $post->id;
- }
+ if($post->save())
+ echo json_encode(array($post->id, $post->created_at));
}
diff --git a/Frontend/Assets/Ajax/createPost.js b/Frontend/Assets/Ajax/createPost.js
index c08f96f..e609d6b 100644
--- a/Frontend/Assets/Ajax/createPost.js
+++ b/Frontend/Assets/Ajax/createPost.js
@@ -7,16 +7,20 @@ function createPost(title, desc) {
$.ajax({
url: '../Backend/controller/upload.php',
type: 'POST',
+ dataType: 'json',
data: data,
success: function (data) {
+ var d = new Date(data[1])
$('#table_id').DataTable().row.add([
+ d.getDate() + '/' + (d.getMonth()+1)+'-'+d.getFullYear(),
title,
- desc,
- '',
- '
'
+ '
',
+ '
'
]).draw().node().id = '1234';
},
- error: function () {
+ error: function (data) {
+ console.log("error");
+ console.log(data);
console.log("error");
}
});
diff --git a/Frontend/Assets/Ajax/editPost.js b/Frontend/Assets/Ajax/editPost.js
index 28df8c0..0f62bde 100644
--- a/Frontend/Assets/Ajax/editPost.js
+++ b/Frontend/Assets/Ajax/editPost.js
@@ -1,21 +1,55 @@
-/*function deletePost(id) {
- return $.ajax({
+function editPost(id) {
+ $.ajax({
type: 'POST',
- url: '../Backend/controller/deletePost.php',
- data: {'delete_id':id},
+ url: '../Backend/controller/getPost.php',
+ data: { id: id },
success:function (data) {
- Swal.fire(
- 'Posten er slettet!',
- '',
- 'success'
- )
+ Swal.fire({
+ title: 'Rediger Post',
+ html: '