【问题标题】:What to return from myfeeds.php (server side)从 myfeeds.php 返回什么(服务器端)
【发布时间】:2012-02-24 04:56:33
【问题描述】:

我正在从我的服务器端页面 (getEvents.cfm) 返回以下字符串。我在 ColdFusion 工作。

[
{
    title: 'Event1',
    start: '2012-02-02',
    end: '2012-02-02',
    allDay: 'no'
},
{
    title: 'Event2',
    start: '2012-02-03',
    end: '2012-02-03',
    allDay: 'no'
}
]

但我在页面加载时收到错误“获取事件时出错!”

这是我用来获取事件的代码:

eventSources: [

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

            // any other sources...

]

【问题讨论】:

    标签: jquery jquery-plugins coldfusion fullcalendar coldfusion-9


    【解决方案1】:

    首先allDay 应该是真/假而不是否/是。其次,返回字符串应该是这样的:

     [{
        "title": 'Event2',
        "start": '2012-02-03',
        "end": '2012-02-03',
        "allDay": 'false'
    }]
    

    【讨论】:

    • Adil,是的,不要忘记 JSON 对象必须将键和值都包含在字符串中。 json.org/example.html
    • 谢谢,它成功了。我是json的新手。我在以下位置找到格式:arshaw.com/fullcalendar/docs/event_data/Event_Source_Object 可能是他们提供了错误的 json 格式。再次感谢您的帮助
    • 是的 - 您需要引用键以保持区分大小写,否则 ColdFusion 会将它们大写
    【解决方案2】:
    $.getJSON('path_to_your_json_file',function(data){
       $.each(data,function(index,entry){
          //assuming we already have a <div> created and get the id
             //show the JSON data
          $('#div_id_created_earlier').append('
             'Title: ' + entry.title + '<br \/>' + 
             'Start: ' + entry.start + '<br \/>' +
             'End: ' + entry.end + '<br \/>' +
             'All day: ' + entry.allDay + '<br \/><br \/>' +
          ');
       });
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-16
      • 2018-12-14
      相关资源
      最近更新 更多