如何使用Ajax将数据绑定到jquery事件日历

时间:2015-06-26 09:10:08

标签: jquery ajax coldfusion

 $.ajax({
      type: "POST",
      contentType: "application/json",
      data: "{eventdata:" + JSON.stringify(eventToSave) + "}",
      url: "Business/DashboardCfc.cfc?method=funtodayevent&returnFormat=JSON",
      dataType: "json",
      success: function (data) {
           var events = new Array();
           $.map(data.d, function (item, i) {
               var event = new Object();
               event.id = item.Event_id;
               event.start = new Date(item.even_date);
               event.title = item.EventName;
               event.allDay = false;
               events.push(event);
           })
           $('div[id*=calendar]').fullCalendar('addEventSource', events);
           $("#loading").dialog("close");
       },                  
    }
});

1 个答案:

答案 0 :(得分:0)

The question is vague enough that all I can deduce from the title of the question is that the code isn't working for you. Here is what came out of my comments to your questions above:

$.ajax({
    type: "POST",
    contentType: "application/json",
    data: "{eventdata:" + JSON.stringify(eventToSave) + "}",
    url: "Business/DashboardCfc.cfc?method=funtodayevent&returnFormat=JSON",
    dataType: "json",
    success: function (data) {
        var events = new Array();
        $.map(data.d, function (item, i) {
            var event = new Object();
            event.id = item.Event_id;
            event.start = new Date(item.even_date);
            event.title = item.EventName;
            event.allDay = false;
            events.push(event);
        });
        $('div[id*=calendar]').fullCalendar('addEventSource', events);
        $("#loading").dialog("close");
    }
});

I would also advise to use $.map in the correct manner if you are going to get the most benefit out of it.

var events = $.map(data.d, function (item, i) {
   var event = new Object();
   event.id = item.Event_id;
   event.start = new Date(item.even_date);
   event.title = item.EventName;
   event.allDay = false;
   return event;
});