| Issue 1109: | Event source $.ajax "data" as a string | |
| 2 people starred this issue and may be notified of changes. | Back to list |
Hey Adam, First off, thanks for all your work on FullCalendar! It truly is a great plugin. I'm trying to pass all the values of a form with the FullCalendar ajax request using the 'data' option, as described here: http://arshaw.com/fullcalendar/docs/event_data/events_json_feed/ I'm using FullCalendar 1.5.2 with jQuery 1.4.4. Here's my code: $('#calendar').fullCalendar({ events: { url: $('#form').attr('action'), data: $('#form').serialize() }, weekMode: 'variable', header: { left: '', center: 'title', right: 'prev today next' }, buttonText: { prev: 'Previous', next: 'Next', today: 'Today' } }); .formSerialize() just creates a query string with the values, like so: anyTime=1&specificTime=1&unfulfilled=1&fulfilled=1&open=1 But here's the query string of the ajax request made by FullCalendar: ?_=1315516498649&0=a&1=n&2=y&3=T&4=i&5=m&6=e&7=%3D&8=1&9=%26&10=s&11=p&12=e&13=c&14=i&15=f&16=i&17=c&18=T&19=i&20=m&21=e&22=%3D&23=1&24=%26&25=u&26=n&27=f&28=u&29=l&30=f&31=i&32=l&33=l&34=e&35=d&36=%3D&37=1&38=%26&39=f&40=u&41=l&42=f&43=i&44=l&45=l&46=e&47=d&48=%3D&49=1&50=%26&51=o&52=p&53=e&54=n&55=%3D&56=1&start=1312088400&end=1315112400 It works with a regular .ajax() request, however: $.ajax({ url: $('#form').attr('action'), data: $('#form').serialize() }); And the query string it uses in the request: ?anyTime=1&specificTime=1&unfulfilled=1&fulfilled=1&open=1 FullCalendar appears to be splitting out each character and value into a separate numbered query string key. Is this a bug? I'm guessing so, since it works with .ajax(), which is what you're using behind-the-scenes. Any help is appreciated! Thanks! Justin
Oct 2, 2011
right now fullcalendar only accepts a key/value object for the data of an event source. however, since fc claims to support all of $.ajax's options, this is a bug. will fix this
Summary:
event source "data" as a string
Status: Accepted
Jun 13, 2012
Is there a workaround? Best way (I guess) to convert form data into js object: http://stackoverflow.com/questions/1184624/convert-form-data-to-js-object-with-jquery#answer-1186309.
Jun 13, 2012
Yes, that's more-or-less the method I used. Here's the exact code, specific to my context:
var optionsFormDataObject = function () {
var data = {};
$('#formNeedOptions :input:not(:button)').each(function () {
var $input = $(this);
data[$input.attr('name')] = function () {
if ($input.is(':checkbox')) {
return Number($input.is(':checked'));
}
else {
return $input.val();
}
};
});
return data;
};
Each data value is a function so that it's dynamic and not just the value when the "optionsFormDataObject" function is called. Hope that helps.
Aug 13, 2013
(No comment was entered for this change.)
Labels:
Type-BehaviorMod
Aug 14, 2013
(No comment was entered for this change.)
Summary:
Event source $.ajax "data" as a string
(was: event source "data" as a string)
Labels: -Type-BehaviorMod Type-Behavior
Apr 19, 2015
(No comment was entered for this change.)
Labels:
-Type-Behavior Type-Feature
Aug 21, 2015
Discussion for this issue has moved to the following URL: https://github.com/fullcalendar/fullcalendar/issues/1376 This is because Google Code is shutting down. Apologies if you are being pestered with these notifications. This is a one-time event. Happy coding, Adam
Status:
ExportedToGithub
|
|
| ► Sign in to add a comment |
I should also mention, I'm trying to do this instead of hard coding each field into the 'data' object: data: { order: function () { return $('#formNeedOptionsSortBy').val(); }, anyTime: function () { return Number($('#formNeedOptionsAnyTime').is(':checked')); }, specificTime: function () { return Number($('#formNeedOptionsSpecificTime').is(':checked')); }, unfulfilled: function () { return Number($('#formNeedOptionsUnfulfilled').is(':checked')); }, fulfilled: function () { return Number($('#formNeedOptionsFulfilled').is(':checked')); }, open: function () { return Number($('#formNeedOptionsOpen').is(':checked')); }, closed: function () { return Number($('#formNeedOptionsClosed').is(':checked')); } }