I’m working on a CodeIgniter project and I’m newbie to ajax/jquery. I’m using fullCalendar. In my my view I want to post the date of an event and then post it to the controller. Here is my CalendarView.php
$(document).ready(function() {
$('#calendar').fullCalendar({
dayClick: function(date, allDay, jsEvent, view) {
add_event(date);
},
events: 'https://www.google.com/calendar/feeds/myLogin%40gmail.com/public/basic'
});
});
//Ajax call
function add_event(date) {
$.ajax({
type: 'POST',
url: '<?php echo site_url()."/welcome/add_event/"; ?>',
data:{ eventsJson: JSON.stringify(date) },
dataType : "json",
success: function (response) {
alert(response);
}
});
}
In my controller, here is what I do:
$date= $this->input->post('data');
Could anyone help me ?
In the controller to receive the
eventsJSONyou’d do:Now
$eventsJSONcontains an array with your json data. However, if you’re only sending back the date you don’t need to pass it back as JSON, pluseventsJSONis a bad name for it. In this case you could simply change the data part of the ajax call like:And in your controller: