JQuery FullCalendar 不显示来自 aspx 页面的事件

发布于 2024-10-30 21:35:57 字数 3675 浏览 6 评论 0原文

我通过从 aspx 页面动态获取事件来实现 JQuery FullCalendar。但它没有在日历上显示事件。但如果我手动将页面响应添加到事件属性中,它就可以正常工作。有人可以帮忙看看会出现什么问题吗?这是我的代码。

$('#calendar').fullCalendar({
        theme: true,
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        //events: "GetCalendarEvents.aspx?id=2612&role=supervisor"  --->not working
 // works fine if i add the above page's response to the events manually as shown below
        events: [
                {
                    "id": 1,
                    "title": "Family Sick - Unsubstantiated",
                    "start": "2011-03-21 08:00:00",
                    "end": "2011-03-22 17:00:00",
                    "editable": false,
                    "url": "LeaveRequestForm.aspx?id=1"
                },
                {
                    "id": 2,
                    "title": "Family Medical Leave",
                    "start": "2011-04-25 13:00:00",
                    "end": "2011-04-25 17:00:00",
                    "editable": false,
                    "url": "LeaveRequestForm.aspx?id=1"
                },
                {
                    "id": 3,
                    "title": "Vacation",
                    "start": "2011-04-14 08:00:00",
                    "end": "2011-04-16 17:00:00",
                    "editable": false,
                    "url": "LeaveRequestForm.aspx?id=2"
                },
                {
                    "id": 4,
                    "title": "Training",
                    "start": "2011-04-12 08:00:00",
                    "end": "2011-04-12 17:00:00",
                    "editable": false,
                    "url": "LeaveRequestForm.aspx?id=2"
                }

            ]

    });

GetCalendarEvents.aspx 代码隐藏:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim dbAPD As DBAPDData = New DBAPDData()
    Dim util As Utils = New Utils()
    Dim approverID As String = ""
    Dim approverRole As String = ""

    If (Request.QueryString("id") IsNot Nothing) Then
        approverID = Request.QueryString("id").Trim()
    End If

    If (Request.QueryString("role") IsNot Nothing) Then
        approverRole = Request.QueryString("role").Trim()
    End If

    Dim eventsList As List(Of CalendarEvent) = New List(Of CalendarEvent)()

    Dim ds As DataSet = dbAPD.GetLeaveRequestDetailsByApprover(approverID, approverRole, 2) 'LeaveStatusCode = 2 --> Approved
    If (ds.Tables(0).Rows.Count > 0) Then

        For Each dr As DataRow In ds.Tables(0).Rows

            Dim calEvent As CalendarEvent = New CalendarEvent()

            calEvent.id = If(IsDBNull(dr("LeaveRequestDetailsID")), 0, Convert.ToInt32(dr("LeaveRequestDetailsID")))
            calEvent.title = If(IsDBNull(dr("LeaveCode")), "", dbAPD.GetLeaveCodeDescription(Convert.ToString(dr("LeaveCode"))))
            calEvent.url = If(IsDBNull(dr("LeaveRequestID")), "", "LeaveRequestForm.aspx?id=" + Convert.ToString(dr("LeaveRequestID")))


            calEvent.start = If(IsDBNull(dr("FromDate")), "", String.Format("{0:yyyy-MM-dd HH:mm:ss}", Convert.ToDateTime(dr("FromDate"))))
            calEvent.end = If(IsDBNull(dr("ToDate")), "", String.Format("{0:yyyy-MM-dd HH:mm:ss}", Convert.ToDateTime(dr("ToDate"))))

            eventsList.Add(calEvent)

        Next

    End If

    ' Serialize the return value .
    Dim js As New System.Web.Script.Serialization.JavaScriptSerializer
    Dim strEvents As String = js.Serialize(eventsList)

    Response.Clear()
    Response.Write(strEvents)

End Sub

I have implemented JQuery FullCalendar by fetching the events dynamically from an aspx page. But it is not displaying the events on the calendar. But if I manually add the page response to the events attribute, it works fine. Can anybody please help what would be the issue? Here is my code.

$('#calendar').fullCalendar({
        theme: true,
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },
        //events: "GetCalendarEvents.aspx?id=2612&role=supervisor"  --->not working
 // works fine if i add the above page's response to the events manually as shown below
        events: [
                {
                    "id": 1,
                    "title": "Family Sick - Unsubstantiated",
                    "start": "2011-03-21 08:00:00",
                    "end": "2011-03-22 17:00:00",
                    "editable": false,
                    "url": "LeaveRequestForm.aspx?id=1"
                },
                {
                    "id": 2,
                    "title": "Family Medical Leave",
                    "start": "2011-04-25 13:00:00",
                    "end": "2011-04-25 17:00:00",
                    "editable": false,
                    "url": "LeaveRequestForm.aspx?id=1"
                },
                {
                    "id": 3,
                    "title": "Vacation",
                    "start": "2011-04-14 08:00:00",
                    "end": "2011-04-16 17:00:00",
                    "editable": false,
                    "url": "LeaveRequestForm.aspx?id=2"
                },
                {
                    "id": 4,
                    "title": "Training",
                    "start": "2011-04-12 08:00:00",
                    "end": "2011-04-12 17:00:00",
                    "editable": false,
                    "url": "LeaveRequestForm.aspx?id=2"
                }

            ]

    });

GetCalendarEvents.aspx codebehind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim dbAPD As DBAPDData = New DBAPDData()
    Dim util As Utils = New Utils()
    Dim approverID As String = ""
    Dim approverRole As String = ""

    If (Request.QueryString("id") IsNot Nothing) Then
        approverID = Request.QueryString("id").Trim()
    End If

    If (Request.QueryString("role") IsNot Nothing) Then
        approverRole = Request.QueryString("role").Trim()
    End If

    Dim eventsList As List(Of CalendarEvent) = New List(Of CalendarEvent)()

    Dim ds As DataSet = dbAPD.GetLeaveRequestDetailsByApprover(approverID, approverRole, 2) 'LeaveStatusCode = 2 --> Approved
    If (ds.Tables(0).Rows.Count > 0) Then

        For Each dr As DataRow In ds.Tables(0).Rows

            Dim calEvent As CalendarEvent = New CalendarEvent()

            calEvent.id = If(IsDBNull(dr("LeaveRequestDetailsID")), 0, Convert.ToInt32(dr("LeaveRequestDetailsID")))
            calEvent.title = If(IsDBNull(dr("LeaveCode")), "", dbAPD.GetLeaveCodeDescription(Convert.ToString(dr("LeaveCode"))))
            calEvent.url = If(IsDBNull(dr("LeaveRequestID")), "", "LeaveRequestForm.aspx?id=" + Convert.ToString(dr("LeaveRequestID")))


            calEvent.start = If(IsDBNull(dr("FromDate")), "", String.Format("{0:yyyy-MM-dd HH:mm:ss}", Convert.ToDateTime(dr("FromDate"))))
            calEvent.end = If(IsDBNull(dr("ToDate")), "", String.Format("{0:yyyy-MM-dd HH:mm:ss}", Convert.ToDateTime(dr("ToDate"))))

            eventsList.Add(calEvent)

        Next

    End If

    ' Serialize the return value .
    Dim js As New System.Web.Script.Serialization.JavaScriptSerializer
    Dim strEvents As String = js.Serialize(eventsList)

    Response.Clear()
    Response.Write(strEvents)

End Sub

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你不是我要的菜∠ 2024-11-06 21:35:57

我想通了这个问题。在“GetCalendarEvents.aspx”代码隐藏文件中,我在 Response.Write() 之后添加了以下行,并且工作正常。

Response.End()

谢谢

I figured out the issue. In "GetCalendarEvents.aspx" code-behind file, I added the following line after Response.Write() and it worked fine.

Response.End()

Thanks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文