【问题标题】:Fullcalendar Event drop and ajaxFullcalendar 事件删除和 ajax
【发布时间】:2013-08-06 20:48:12
【问题描述】:

我目前正在使用出色的 Jquery 插件 - Fullcalendar,但我遇到了问题。我使用 eventDrop 侦听器,我想使用 Ajax 将事件信息发送到我的服务器端。

我的代码如下:

eventDrop: function (event, dayDelta) {

                $.ajax({
                    url: ("/PSAdmin/RFCalendar/DragEvent"),
                    data: ({
                        type: event.className,
                        delta: dayDelta,
                        newDate: event.start,
                        newTitle: event.title
                    }),
                    type: "POST",
                    success: function (data) {
                        $('#calendar').empty();
                        loadCalendar();
                    },
                    error: function (xhr, status, error) {
                        alert("fail");
                    }
                });
}

我的问题是,一旦我尝试将包含的任何变量发送到事件对象中,它就不起作用。例如,仅将 dayDelta 发送到服务器端有效,但 event.something 没有。

如果之前有人偶然发现这个问题,或者如果您知道可能导致问题的原因,请告诉我。

【问题讨论】:

  • 您的代码应该可以完美运行。 Please check in console that your event.something have their values. 您可以将 event.something 缓存到变量中,然后使用这些变量作为数据对象传递。
  • 我提醒了每个值,它们都很好,但是当它们到达我的服务器时它们是空的。
  • 您是否使用浏览器的开发工具或使用 Fiddler 或类似工具检查网络请求?

标签: jquery ajax plugins fullcalendar


【解决方案1】:

很遗憾,我无法弄清楚为什么 ajax 查询不能正常工作,我不得不做我原本不想做的事情。

if (event.className == "holiday") {
                    var className = "holiday";
                }

                //build date
                var date = event.start.getMonth()+1 + "/" + event.start.getDate() + "/" + event.start.getFullYear();
                alert(date);

                $.ajax({
                    url: ("/PSAdmin/RFCalendar/DragEvent/"),
                    data: ({
                        className: className,
                        delta: dayDelta,
                        newDate: date,
                        newTitle: event.title
                    }),
                    type: "POST",
                    success: function (data) {
                        $('#calendar').empty();
                        loadCalendar();
                    },
                    error: function (xhr, status, error) {
                        alert("fail");
                    }
                });

它既丑陋又耗时,但至少它有效。我还有其他优先事项要处理,但如果您对此问题有任何线索,请告诉我。

谢谢, 格雷格

【讨论】:

    【解决方案2】:

    迟到的答案,但我遇到了一个类似的问题,没有任何东西发送到服务器。尝试了一切,缓存以及使用 jquery 扩展和复制对象。

    对我有用的是查看请求的标题。他们似乎总是有数据。

    我最终得到了这个代码服务器端。不是我想要的,但它可能会帮助试图解决同样问题的人!

    C#

    [HttpGet]
        public void UpdateOrderData(object orderObj)
        {
            var obj = new
            {
                start = System.Web.HttpUtility.UrlDecode(HttpContext.Current.Request.QueryString["orderObj[start]"]),
                end = System.Web.HttpUtility.UrlDecode(HttpContext.Current.Request.QueryString["orderObj[end]"]),
                date = System.Web.HttpUtility.UrlDecode(HttpContext.Current.Request.QueryString["orderObj[date]"]),
                resourceId = System.Web.HttpUtility.UrlDecode(HttpContext.Current.Request.QueryString["orderObj[resourceId]"]),
                orderId = System.Web.HttpUtility.UrlDecode(HttpContext.Current.Request.QueryString["orderObj[orderId]"]),
            };
    
            calendarUnitOfWork.CustomDataRepository.UpdateOrderData(obj);
        }
    

    Javascript

     myModel.eventDrop = function(event, delta, revertFunc, jsEvent, ui, view ) 
     {
         calUOW.orderrepository.updateOrderData({
                start: event.start.format(),
                end: event.end.format(),
                date: event.start.format("YYYY-MM-DD"),
                resourceId: event.resourceId,
                orderId: event.orderId
            });
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-18
      • 1970-01-01
      相关资源
      最近更新 更多