jquery fullcalendar send custom parameter and refresh calendar with JSON-open source projects arshaw/fullcalendar

I have a problem of duplication events. When I create an event always the last event is duplicate. I am required to use location.reload() to avoid that.Someone can help me find a solution. This is my code :

$(document).ready(function() {

            var date = new Date();
            var d = date.getDate();
            var m = date.getMonth();
            var y = date.getFullYear();




            /* initialize the calendar
            -----------------------------------------------------------------*/

            var calendar = $('#calendar').fullCalendar({
                allDayDefault: false,
                minTime: 7,
                maxTime: 20,
                editable: true,
                ignoreTimezone: false,

                header: {
                    left: 'prev,next today',
                    center: 'title'
                    //right: 'resourceDay,month,agendaWeek',
                    //right: 'resourceDay'
                },
                titleFormat: 'ddd, MMM dd, yyyy',
                defaultView: 'resourceDay',

                resources: [
                    {
                        name: 'David Boudreau',
                        id: '71'
                    },
                    {
                        name: 'Frédéric Cyr',
                        id: '50'

                    },
                    {
                        name: 'Guillaume R.',
                        id: '12'
                    }
                    ,
                    {
                        name: 'Jonathan Morin',
                        id: '58'
                    }
                    ,                                               
                ],

                events: "/events.php",

                // affiche img done pour chaque event
                 eventRender: function(event, element) {
                    if(event.done == 1)
                    {
                        $('#fc-event-done_'+event.id).show();
                    }
                },

                /*add event*/
                selectable: true,
                selectHelper: true,
                select: function(start, end, allDay, event, resourceId) {

                start = $.fullCalendar.formatDate(start, "yyyy-MM-dd HH:mm:ss");
                end = $.fullCalendar.formatDate(end, "yyyy-MM-dd HH:mm:ss");

                 $("#name_title").html('

Nouvelle Tâche

');
                 $('#duree').hide();
                 $('#del').hide();
                 $('#myModal').modal('show');
                 $('#title_tache').focus();
                 var data  = '';

                 $("#submit").click(function(){  
                     var title = $('#title_tache').val();
                     var color = $('input[name=lst_type]:checked').val();
                     var datefin = $('#datepicker').val();


                     $.ajax({
                         url: 'add_events.php',
                         data: 'title='+ title+'&start='+ start +'&end='+ end +'&color='+ color +'&datefin='+ datefin +'&resourceId=' + resourceId,
                         type: "POST",
                         success: function(data) {

                            $("#tacheform").trigger('reset'); //jquery 
                             $('#myModal').modal('hide');

                             $("#calendar").fullCalendar('refetchEvents');
                              $("#calendar").fullCalendar('unselect');

                             //location.reload();
                         }
                     });

                 });
                 //$("#tacheform").trigger('reset'); //jquery 
                $("#calendar").fullCalendar('unselect');

                },

                /*edit info event*/
                eventClick: function(calEvent, jsEvent, view) {
                 //console.log('dentro eventClick');
                    $("#name_title").html('

Mise à jour

');
                    $('#myModal').modal('show'); 
                    $('#title_tache').val(calEvent.title);
                    $('#datepicker').val(calEvent.datefin);
                    //console.log(calEvent.done);
                    if(calEvent.done == 1){ $('#done').prop('checked', true);}
                    else{$('#done').prop('checked', false);}


                     start1 = $.fullCalendar.formatDate(calEvent.start, "yyyy-MM-dd HH:mm:ss");
                     end1 = $.fullCalendar.formatDate(calEvent.end, "yyyy-MM-dd HH:mm:ss");
                     Id = calEvent.id;
                     resource =  calEvent.resourceId;
                     bdcolor = calEvent.backgroundColor;
                     /*select color from database*/
                     if(bdcolor != ''){ 
                        if(bdcolor == '#f39c11'){$("#lst_type1").prop("checked", true); }else{$("#lst_type1").prop("checked", false);}
                        if(bdcolor == '#2ecd71'){$("#lst_type2").prop("checked", true); }else{$("#lst_type2").prop("checked", false);}
                        if(bdcolor == '#5cade2'){$("#lst_type3").prop("checked", true); }else{$("#lst_type3").prop("checked", false);}
                     }


                     /*calcul hours for event*/ 
                     duration  = timediff(calEvent.start,calEvent.end);
                     $('#duration').val(duration);


                     //update event
                     $("#submit").click(function(){            
                        var title1 = $('#title_tache').val();
                        var color = $('input[name=lst_type]:checked').val();
                        var datefin = $('#datepicker').val();
                        var done = 0;

                        if( $('#done').is(':checked') ){
                            done = $('#done').val();
                        }
                        //calEvent.title =title;
                         $.ajax({
                            type: "POST",
                            url: "update_events.php",
                            data: 'title='+ title1+'&start='+ start1 +'&end='+ end1 +'&resourceId='+ resource +'&color='+ color +'&datefin='+ datefin +'&done='+ done + '&id=' + Id,
                                success: function(data){
                                      //$("#thanks").html(msg)
                                    $("#tacheform").trigger('reset'); //jquery 
                                     $('#myModal').modal('hide');
                                     $("#calendar").fullCalendar('refetchEvents');
                                     calendar.fullCalendar('unselect');
                                     location.reload();

                                },
                            error: function(){alert("Erreur lors de l'update");}});
                     });

                    //delete event
                     $("#del").click(function(){            
                         $.ajax({
                            type: "POST",
                            url: "delete_event.php",
                            data: 'id=' + Id,
                                success: function(data){
                                      //$("#thanks").html(msg)
                                    //$("#tacheform").trigger('reset'); //jquery  
                                    $("#myModal").modal('hide');
                                    $("#calendar").fullCalendar('refetchEvents');
                                    calendar.fullCalendar( 'unselect');

                                },
                            error: function(){alert("Erreur lors delete");}});
                     });
                    calendar.fullCalendar( 'unselect');
                },
                /*update event*/
                editable: true,
                eventDrop: function(event, delta) {
                 start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss");
                 end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss");
                 datefin  = event.datefin;
                 done  = event.done;
                 resource =  event.resourceId;
                 $.ajax({
                 url: 'update_events.php',
                 data: 'title='+ event.title+'&start='+ start +'&end='+ end +'&resourceId='+ resource +'&color='+ event.backgroundColor+'&datefin='+datefin+'&done='+done+'&id='+ event.id ,
                 type: "POST",
                 success: function(json) {
                 //alert("OK");
                 //console.log('update drop'); 
                   $.pnotify({
                        title: 'Mise à jour réussi',
                        type: 'success'
                    });
                 }
                 });
                },
                eventResize: function(event) {
                 start = $.fullCalendar.formatDate(event.start, "yyyy-MM-dd HH:mm:ss");
                 end = $.fullCalendar.formatDate(event.end, "yyyy-MM-dd HH:mm:ss");
                 datefin  = event.datefin;
                 done  = event.done;
                 resource =  event.resourceId;
                 $.ajax({
                 url: 'update_events.php',
                 data: 'title='+ event.title+'&start='+ start +'&end='+ end +'&resourceId='+ resource +'&color='+ event.backgroundColor+'&datefin='+datefin+'&done='+done+'&id='+ event.id ,
                 type: "POST",
                 success: function(json) {
                    console.log('update rezise'); 
                   $.pnotify({
                        title: 'Mise à jour réussi',
                        type: 'success'
                    });
                 }
                 });

                },



            });