fullCalendar事件不显示,即使正确的JSON饲料 [英] fullCalendar events not showing even though correct JSON feed

查看:878
本文介绍了fullCalendar事件不显示,即使正确的JSON饲料的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为一堆别人的我已经让我的JSON饲料事件在日历中呈现的一个问题。这个问题往往是错的JSON格式化,但事实并非如此,因为我已经有JSONlint和硬codeD上的JSON饲料中的Site.Master与积极的结果证实它。

As a bunch of others I have a problem getting my JSON feed events to render in the calendar. The problem is often wrong JSON formating, but this is not the case since I've validated it with JSONlint and hardcoded the JSON feed in Site.Master with positive result.

Firebug是正确得到JSON响应,但是现在还没有显示fullCalendar起来。我的想法。

FireBug is getting the JSON response correctly but it is still not showing up in fullCalendar. I'm out of ideas.

Firebug的回应:
[{\"id\":1,\"title\":\"TESTTITLE\",\"info\":\"INFOINFOINFO\",\"start\":\"2012-08-20T12:00:00\",\"end\":\"2012-08-20T12:00:00\",\"user\":1}]

The FireBug response: [{"id":1,"title":"TESTTITLE","info":"INFOINFOINFO","start":"2012-08-20T12:00:00","end":"2012-08-20T12:00:00","user":1}]

JSON.aspx

JSON.aspx

public partial class JSON : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
    // Get events from db and add to list.
    DataClassesDataContext db = new DataClassesDataContext();
    List<calevent> eventList = db.calevents.ToList();

    // Select events and return datetime as sortable XML Schema style.
    var events = from ev in eventList
                 select new
                 {
                     id = ev.event_id,
                     title = ev.title,
                     info = ev.description,
                     start = ev.event_start.ToString("s"),
                     end = ev.event_end.ToString("s"),
                     user = ev.user_id
                 };

    // Serialize to JSON string.
    JavaScriptSerializer jss = new JavaScriptSerializer();
    String json = jss.Serialize(events);

    Response.Write(json);
    Response.End();
   }
}

Site.master母

Site.master

<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />    
<link href='fullcalendar/fullcalendar.css' rel='stylesheet' type='text/css' />
<script src='jquery/jquery-1.7.1.min.js' type='text/javascript'></script>
<script src='fullcalendar/fullcalendar.js' type='text/javascript' ></script>
<script type="text/javascript">
     $(document).ready(function () {
         $('#fullcal').fullCalendar({

            eventClick: function() {
                alert('a day has been clicked!');
            },
          events: 'JSON.aspx' 
         })
     });
</script>

我已经扫描相关的问题了好几天,但他们都不似乎解决我的...

I've been scanning related questions for days but none of them seems to fix mine...

推荐答案

试试这个,你必须有在aspx文件一个WebMethod的fullcalendar可以异步调用

Try this , you have to have a webmethod in aspx file that fullcalendar can call asynchronously

       $(document).ready(function () {
        $('#fullcal').fullCalendar({
        eventClick: function() {
            alert('a day has been clicked!');
        }, 
            events: function (start, end, callback) {
            $.ajax({
                type: "POST",    //WebMethods will not allow GET
                url: "json.aspx/GetEvents",   //url of a webmethod - example below
                data: "{'userID':'" + $('#<%= hidUserID.ClientID %>').val() + "'}",  //this is what I use to pass who's calendar it is 
                //completely take out 'data:' line if you don't want to pass to webmethod - Important to also change webmethod to not accept any parameters 
                contentType: "application/json; charset=utf-8",  
                dataType: "json",
                success: function (doc) {
                    var events = [];   //javascript event object created here
                    var obj = $.parseJSON(doc.d);  //.net returns json wrapped in "d"
                    $(obj.event).each(function () { //yours is obj.calevent                          
                            events.push({
                            title: $(this).attr('title'),  //your calevent object has identical parameters 'title', 'start', ect, so this will work
                            start: $(this).attr('start'), // will be parsed into DateTime object    
                            end: $(this).attr('end'),
                            id: $(this).attr('id')
                        });
                    });                     
                    callback(events);
                }
            });
        }
       })

那么这将是在json.aspx

then this would be in json.aspx

[WebMethod(EnableSession = true)]
public static string GetEvents(string userID)
{
    DataClassesDataContext db = new DataClassesDataContext();
List<calevent> eventList = db.calevents.ToList();

// Select events and return datetime as sortable XML Schema style.
var events = from ev in eventList
             select new
             {
                 id = ev.event_id,
                 title = ev.title,
                 info = ev.description,
                 start = ev.event_start.ToString("s"),
                 end = ev.event_end.ToString("s"),
                 user = ev.user_id
             };

// Serialize to JSON string.
JavaScriptSerializer jss = new JavaScriptSerializer();
String json = jss.Serialize(events);
return json;
}

这篇关于fullCalendar事件不显示,即使正确的JSON饲料的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆