简体   繁体   English

如何让 jquery fullcalendar 将附加参数传递给我的 json 提要脚本

[英]How do get jquery fullcalendar to pass additional parameters to my json feed script

My code is as follows我的代码如下

jQuery('#calendar').fullCalendar({
    weekMode: 'liquid',
    events: themeforce.events,
    eventRender: function (event, element) {
        element.find('span.fc-event-title').html(element.find('span.fc-event-title').text());           
    }
});

where themeforce.events is a variable containing an encoded url of the json feed a php file - all works well.其中themeforce.events是一个变量,包含 json 的编码 url 提供一个 php 文件 - 一切正常。

I tried replacing events: themeforce.events, with我尝试替换事件:themeforce.events,

events: {
    url: themeforce.events,
    type: 'POST',
    data: {
        custom_param1: 'something',
        custom_param2: 'somethingelse'
    },

However now the calendar fails to load.但是现在日历无法加载。

What can I do?我能做什么?

I wanted the start and end times for a post ajax request and it took me a bit of time to work it out.我想要一个 post ajax 请求的开始和结束时间,我花了一些时间来解决它。

This might help you:这可能会帮助您:

events: function(start, end, timezone, callback) {
$.ajax({
    url: url,
    type: 'POST',
    dataType: 'json',
    data: {
        start: start.format(),
        end: end.format(),
        custom_param1: 'value 1',
        custom_param2: 'value 2',
    },
    error: function () {
        alert('there was an error while fetching events!');
    },
    success: function(doc) {
        var events = [];

        $.each(doc,function (index, e) {
            events.push(e);
        });

        callback(events);
    }
});
}

You should use extraParams as explained in doc : https://fullcalendar.io/docs/events-json-feed您应该按照文档中的说明使用 extraParams: https ://fullcalendar.io/docs/events-json-feed

var calendar = new Calendar(calendarEl, {

eventSources: [

// your event source
{
  url: '/myfeed.php',
  method: 'POST',
  extraParams: {
    custom_param1: 'something',
    custom_param2: 'somethingelse'
  },
  failure: function() {
    alert('there was an error while fetching events!');
  },
  color: 'yellow',   // a non-ajax option
  textColor: 'black' // a non-ajax option
}

// any other sources...

]

});

Also be sure your feed's url return raw json data array !还要确保您的提要的 url 返回原始 json 数据数组!

Just put "data" instead of "extraParams" in "events"只需在“事件”中放置“数据”而不是“extraParams”

  events: {
    url: 'service.php',
    method: 'POST',
    data: {
        custom_param1: 'something',
        custom_param2: 'somethingelse'
    },
    failure: function() {
        alert('there was an error while fetching events!');
    },
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM