0

I am using a jquery calendar that looks like this:

$(document).ready(function () {
    $('#calendar').eCalendar({

 weekDays: ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'],
    months: ['Janvier', 'Fevrier', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Decembre'],
    textArrows: {previous: '<', next: '>'},
    eventTitle: 'Evenements',
    url: '',

    events: [

   { title: 'title', description: 'description', datetime: new Date (2015,07,01)} 


    ]});
});
</script>

To get the events, I connect to a mysql database and store the result in a php variable such as:

 $event={ title: 'title', description: 'description', datetime: new Date:   (2015,07,01)};

I can't figure out how to put this $event into the jquery script so that it reads it.

I tried for exemple:

$(document).ready(function () {
    $('#calendar').eCalendar({
    ........
    ........
    events: [

   <?php echo $event ?>

    ]});
});

Which doesn't work. Any idea?

Thanks

8
  • 1
    if $event has the correct value, it should work. Can you post the output of your browser in the question (source code)? Commented Jul 8, 2015 at 10:01
  • is $event a string or an array? (the php one) Commented Jul 8, 2015 at 10:02
  • did you try to add quotes like this '<?php echo $event ?>'? Commented Jul 8, 2015 at 10:02
  • It should work, IF $event IS A STRING. Otherwise, you have to stringify it. Commented Jul 8, 2015 at 10:04
  • try <?php echo json_encode($event); ?> Commented Jul 8, 2015 at 10:04

2 Answers 2

1

You have to be sure that $event is a string. I bet it is an array, please provide a vardump($event);to be sure of that.

If it is an array, try this in place of <?php echo $event; ?>;:

<?php echo serialize($event); ?>;

Sign up to request clarification or add additional context in comments.

Comments

0

Perhaps the problem is an error, excess colon after new Date:

$event="{ title: 'title', description: 'description', datetime: new Date: (2015,07,01)};"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.