ajax - Event Object is holding previous event properties in Full Calendar -
i've got problem fullcalendar , looking solution without success. use eventclick open overlay form data of current event. works great until change mind , don't want edit event one. , causes ajax send request 2 times, once opened event (which ready edit form not submitted) , once event edited , submitted.
$('#sc-calendar').fullcalendar({ eventclick: function(event) { //opening overlay form window $('#submit-event-update').bind('click',function() { //click submit $.ajax({ type: "get", url: "event_update", data: "id="+event.id+"&title="+event.title+"&start="+event.start+"&end="+event.end, cache: false, success: function() { $('#submit-event-update').unbind(); $('#sc-calendar').fullcalendar('updateevent',event); } }); }); } }); this starting nightmare. please help!
it seems me there problem onclick event listener #submit-event-update.
you should modify code in way:
$('#sc-calendar').fullcalendar({ eventclick: function(event) { //opening overlay form window //assign event id of event global variable event_id event_id = event.id; } }); $('#submit-event-update').bind('click',function() { //click submit $.ajax({ type: "get", url: "event_update", data: "id=" + event_id + ..., //note how event.id not used anymore cache: false, success: function() { $('#sc-calendar').fullcalendar('updateevent',event); } }); }); i changed bind onclick event handler button once opposed every time event clicked. assign variable event_id holds value of current event's id.
now, explanation. said:
everything works great until change mind , don't want edit event one.
what happens when click on event?
you bind onclick event #submit-event-update. if click button, go success() callback of ajax call , unbind button. if change mind , don't click submit button? now, have 1 onclick listener old data tied button. when pick event, have 2 event listeners tied same button , hence, an ajax request sent 2 times.
it might worth reading on how javascript handles event binding here.
Comments
Post a Comment