v0.0.8 Ajax now works with backend
This commit is contained in:
parent
c7fa37a3ae
commit
4ce94621a7
|
@ -4,19 +4,17 @@ require "../../bootstrap.php";
|
||||||
|
|
||||||
use Backend\Model\Post;
|
use Backend\Model\Post;
|
||||||
|
|
||||||
//Chek if the user did press the button on the home pages
|
//Create a new initialize
|
||||||
if(isset($_POST['createPost'])){
|
$post = new Post();
|
||||||
//Create a new initialize
|
|
||||||
$post = new Post();
|
|
||||||
|
|
||||||
//Get the data from post and save it to the post model
|
//Get the data from post and save it to the post model
|
||||||
$post->title = $_POST['title'];
|
$post->title = $_POST['title'];
|
||||||
$post->description = $_POST['description'];
|
$post->description = $_POST['description'];
|
||||||
|
|
||||||
//Call the save function.
|
//Call the save function.
|
||||||
if(!$post->save()){
|
if(!$post->save()){
|
||||||
return http_response_code(400);
|
return http_response_code(400);
|
||||||
}else{
|
}else{
|
||||||
return http_response_code(200);
|
return http_response_code(200);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ use Illuminate\Database\Capsule\Manager as Capsule;
|
||||||
|
|
||||||
Capsule::schema()->create('posts', function ($table) {//Note til mig selv, husk at din database table skal ende med "s" hvis du faa en lang fejl besked
|
Capsule::schema()->create('posts', function ($table) {//Note til mig selv, husk at din database table skal ende med "s" hvis du faa en lang fejl besked
|
||||||
$table->increments('id');
|
$table->increments('id');
|
||||||
$table->string('title');
|
$table->string('title')->nullable(false);
|
||||||
$table->longtext('description');
|
$table->longtext('description')->nullable(false);
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
|
@ -1,22 +1,15 @@
|
||||||
$("#submit").click(function(){
|
$("#submit").click(function(){
|
||||||
var $title = $("#title");
|
|
||||||
var $description = $("#description");
|
|
||||||
|
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
title: $title.val(),
|
title: $("#title").val(),
|
||||||
description: $description.val(),
|
description: $("#description").val(),
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(data);
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '../Backend/controller/upload.php',
|
url: '../Backend/controller/upload.php',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
data: data,
|
data: data,
|
||||||
contentType: 'application/json; charset=utf-8',
|
success: function (data) {
|
||||||
success: function () {
|
console.log(data)
|
||||||
console.log("Dansker bingo")
|
|
||||||
},
|
},
|
||||||
error: function () {
|
error: function () {
|
||||||
console.log("error");
|
console.log("error");
|
||||||
|
|
|
@ -13,6 +13,4 @@ $( document ).ready(function() {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,8 @@ use Backend\Model\Post;
|
||||||
<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" id="title" name="title">
|
<input type="text" id="title" name="title" maxlength="255">
|
||||||
<input type="text" id="description" name="description">
|
<input type="text" id="description" name="description" maxlength="2000">
|
||||||
<button id="submit" name="createPost">Opret opslag</button>
|
<button id="submit" name="createPost">Opret opslag</button>
|
||||||
<!-- </form>-->
|
<!-- </form>-->
|
||||||
<hr>
|
<hr>
|
||||||
|
@ -49,4 +49,4 @@ use Backend\Model\Post;
|
||||||
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue