I'm able to select a value from database and throw it inside a <div>.
My problem is, I don't know how to do so and follow the MVC rules, as I'm using Laravel framework.
Here is what I've done so far:
Index.php
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://code.jquery.com/jquery-2.2.3.min.js" integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="script.js"></script>
</head>
<body>
<div id="wrapper">
<input type="button" id="btn" value="Click Me :)"></input>
</div>
</body>
</html>
Ajax.php
<?php
include ('db.php');
$pdo = connect();
$dados = $pdo->prepare("SELECT field FROM table WHERE id = ?");
$dados->execute(array("2"));
$usr = $dados->fetch(PDO::FETCH_ASSOC);
echo "<p> Nome:" .$usr["nome"]. "</p>"; //Teste
Script.js
$(document).ready(function(){
$('#btn').click(function(){
$.ajax({
url: "ajax.php",
type: "GET",
dataType: "html", //expected return type
success: function(response){
$('#calendario').fullCalendar(
'renderEvent',
{
title: 'Novo evento',
start: '2016-04-06T08:00:00', // I need to put the data here
end:'2016-04-06T10:30:00' // And here aswell
}
);
}
})
});
});
I made this as a test, and it's working... How may I do the same using Laravel MVC ? Here I had to create a custom php file (ajax.php) only to make the select. Is there a way to do the same thing using my Controller /Model?