So I'm trying to implement a calendar - fullCalendar to be precise - with AJAX so that Ill be able to store events in database. I followed this http://developer-paradize.blogspot.si/2013/06/jquery-fullcalendar-integration-with.html , but it didn't work with adding events. I modified my code a bit and PHP script that stores data gathered through POST request in database, seems to work fine when I send request with Postman, but when I try to post with AJAX nothing happens. PHP script for adding event data in database:
<?php
$title = $_POST['title'];
$start = $_POST['start'];
$end = $_POST['end'];
$url = $_POST['url'];
try {
$bdd = new PDO('mysql:host=localhost;dbname=tracksto', 'admingZZX92g', 'LwQ1Wwi6N2I3');
} catch(Exception $e) {
exit('Unable to connect to db.');
}
$sql = "INSERT INTO evenement (title, start, end, url) VALUES (:title, :start, :end, :url)";
$q = $bdd->prepare($sql);
$q->execute(array(':title'=>$title, ':start'=>$start, ':end'=>$end, ':url'=>$url));
My AJAX call:
var data = { "title":"Gregor", "start":"2016-05-10 00:00:00", "end":"2016-05-10 00:00:00", "url":"www.renting.si" };
$.ajax({
url: '"http://localhost/gui/calendar/add_events.php',
contentType: "application/x-www-form-urlencoded; charset=utf-8",
data: data,
type: "POST",
success: function(json) {
alert('Added Successfully');
}
});
If I have variables title,start,end,url defined and set data to:
data: 'title='+title+'&start='+start+'&end='+end+'&url='+url,
same thing, nothing happens. In POSTMAN the request looks like this: POSTMAN POST request
The script normally processes this request and stores data in database. Is my AJAX call wrong or is there something else?