PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 22, 2022

[FIXED] FullCalendar - Sending view via ajax

 February 22, 2022     ajax, javascript, jquery, json, php     No comments   

Issue

I am trying to integrate the fullCalendar plugin into a website. The problem I am experiencing is that I am trying to send the current view, wether it be month, agendaDay etc..., as a custom parameter via the json/$.ajax method.

$('#calendar').fullCalendar({
events: {
    url: 'feed.php',
    type: 'POST',
    data: {
        view: $('#calendar').fullCalendar('getView').name
    },
    error: function() {
        alert('there was an error while fetching events!');
    }
}
});

The above is returning any errors but the custom view variable is not being passed along with the normal values.

I have tried the following:

$('#calendar').fullCalendar({
    events: {
        url: 'feed.php?view=' + $('#calendar').fullCalendar('getView').name,
       .......

But this just add ?view=undefined to the ajax call. I know that $('#calendar').fullCalendar('getView').name works as it returns the correct value so it must be something with the line view: $('#calendar').fullCalendar('getView').name but I unsure of what.


Solution

It looks like you are trying to access the fullCalendar before it has been initialized. Try breaking it into separate steps:

$('#calendar').fullCalendar();
var viewName = $('#calendar').fullCalendar('getView').name;
$('#calendar').fullCalendar({
    events: {
        url: 'feed.php',
        type: 'POST',
        data: {
            view: viewName
        },
        error: function() {
            alert('there was an error while fetching events!');
        }
    }
});


Answered By - gilly3
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing