v0.0.7 Try to get ajax to work with backend
This commit is contained in:
parent
4024c0dd99
commit
c7fa37a3ae
|
@ -6,22 +6,17 @@ use Backend\Model\Post;
|
||||||
|
|
||||||
//Chek if the user did press the button on the home pages
|
//Chek if the user did press the button on the home pages
|
||||||
if(isset($_POST['createPost'])){
|
if(isset($_POST['createPost'])){
|
||||||
//Grep the data from post
|
|
||||||
$title = $_POST['title'];
|
|
||||||
$description = $_POST['description'];
|
|
||||||
|
|
||||||
//Create a new initialize
|
//Create a new initialize
|
||||||
$post = new Post();
|
$post = new Post();
|
||||||
|
|
||||||
//Call the Post class and save the user data to the database
|
//Get the data from post and save it to the post model
|
||||||
$post->title = $title;
|
$post->title = $_POST['title'];
|
||||||
$post->description = $description;
|
$post->description = $_POST['description'];
|
||||||
|
|
||||||
//Call the save function.
|
//Call the save function.
|
||||||
if(!$post->save()){
|
if(!$post->save()){
|
||||||
echo "Failed to save the post";
|
return http_response_code(400);
|
||||||
exit();
|
|
||||||
}else{
|
}else{
|
||||||
header("location: ../../Frontend/home.php?Post=UploadSuccess");
|
return http_response_code(200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
$("#submit").click(function(){
|
||||||
|
var $title = $("#title");
|
||||||
|
var $description = $("#description");
|
||||||
|
|
||||||
|
|
||||||
|
var data = {
|
||||||
|
title: $title.val(),
|
||||||
|
description: $description.val(),
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: '../Backend/controller/upload.php',
|
||||||
|
type: 'POST',
|
||||||
|
data: data,
|
||||||
|
contentType: 'application/json; charset=utf-8',
|
||||||
|
success: function () {
|
||||||
|
console.log("Dansker bingo")
|
||||||
|
},
|
||||||
|
error: function () {
|
||||||
|
console.log("error");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
|
@ -4,10 +4,10 @@ function deletePost(id) {
|
||||||
url: '../Backend/controller/deletePost.php',
|
url: '../Backend/controller/deletePost.php',
|
||||||
data: {'delete_id':id},
|
data: {'delete_id':id},
|
||||||
success:function (data) {
|
success:function (data) {
|
||||||
console.log(data);
|
console.log("Delete was a success");
|
||||||
},
|
},
|
||||||
error:function (data) {
|
error:function (data) {
|
||||||
console.log(data);
|
console.log("Delete was not a success");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
|
@ -33,11 +33,11 @@ use Backend\Model\Post;
|
||||||
<a href="../Backend/controller/logout.php">Log ud</a>
|
<a href="../Backend/controller/logout.php">Log ud</a>
|
||||||
<hr>
|
<hr>
|
||||||
<p>Opret post</p>
|
<p>Opret post</p>
|
||||||
<form action="../Backend/controller/upload.php" method="POST">
|
<!--<form action="../Backend/controller/upload.php" method="POST">-->
|
||||||
<input type="text" name="title">
|
<input type="text" id="title" name="title">
|
||||||
<input type="text" name="description">
|
<input type="text" id="description" name="description">
|
||||||
<input type="submit" name="createPost" placeholder="Opret">
|
<button id="submit" name="createPost">Opret opslag</button>
|
||||||
</form>
|
<!-- </form>-->
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@ use Backend\Model\Post;
|
||||||
|
|
||||||
<script src="Assets/Ajax/deletePost.js"></script>
|
<script src="Assets/Ajax/deletePost.js"></script>
|
||||||
<script src="Assets/Ajax/fetchAndDisplayData.js"></script>
|
<script src="Assets/Ajax/fetchAndDisplayData.js"></script>
|
||||||
|
<script src="Assets/Ajax/createPost.js"></script>
|
||||||
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in New Issue