3
Good afternoon, I am trying to upload an event to Fullcalendar. The problem is this
$(document).ready(function() {
$('#calendar').fullCalendar({
header: {
left: 'today',
center: 'prev, title, next',
right: 'month,basicWeek,basicDay'
},
eventClick: function(event) {
$('#modalTitle').html(event.title);
$('#modalBody').html(event.description);
$('#eventUrl').attr('href',event.url);
$('#fullCalModal').modal();
return false;
},
navLinks: true, // can click day/week names to navigate views
editable: true,
eventLimit: true, // allow "more" link when too many events
events:[
<?php include('process.php') ?>
]
});
});
Process.PHP
<?php
$title = "Jose";
$start = "2016-11-01";
echo "{
title: '$title' ,
start: '$start'
}";
?>
This way I can carry, but I would like to know how I do calling a JSON? tried in many ways ($.getJson, $.get, Json.parser(), etc...) Anyone have any tips?
I don’t know AJAX, do you have a website that can tell me? I found the code $. ajax({ url: address, complete: Function(res){ var meuJSON = JSON.parse(res.responseText); console.log(meuJSON); } }); but I need an example to base myself on
– Jose Leandro
@Joseleandro this code that you put in the commentary is a longer way to do what I put in the reply. Take a look here http://answall.com/a/25215/129, but at the bottom is what I put in the answer using the specific and simplified version of jQuery for AJAX + JSON, which is the
getJSON
. You tested my code?– Sergio
@Also interesting: http://answall.com/a/116177/129
– Sergio
My Json condigo is { "events":[ { "title":"Jose", "start":"2016-09-01" } ] } I should modify something?
– Jose Leandro
@Joseleandro already has this json in javascript with getJSON?
– Sergio
My code looks like this: index.php $. getJSON("events.json", Function(Event){ ... Events:[ Event ] } and my Json events.json { "events":[ { "title":"Jose", "start":"2016-09-01" } ] }
– Jose Leandro
Place only the array in JSON, without the "{events:}"
– Sergio
So close, I put as you said, and put the Events: Alert(Event) And the answer I have is [Object Object] I started my search for knowledge again and the only answer I find is that I don’t need JSON.parse, but the error happens if I don’t use itlo and using it is occurring Syntaxerror JSON.parse, and my code is like this: var Objecting = JSON.parse(Event); and my events. Json looks like this: [ { "title":"Jose", "start":"2016-09-01" } ]
– Jose Leandro
The error is: Unexpected Character at line 1 column 2 of the JSON data
– Jose Leandro
@Joseleandro in PHP puts it like this:
echo '[{"title":"Jose", "start":"2016-09-01"}]';
and Javascript as follows: http://jsfiddle.net/hge7Lxza/– Sergio
This way it works, but this way I have to use a php file, know if I could do the same thing only with a file . Json?
– Jose Leandro
@Joseleandro in the same way... http://jsfiddle.net/hge7Lxza/1/ and in the file
.json
only[{"title":"Jose", "start":"2016-09-01"}]
no quotation marks before or after.– Sergio
Good morning, I tested, but it returns [Object Object]. I did a test only with $.get and it’s returning me [ { "title":"Jose", "start":"2016-11-01" } ] which is what I need to return to Events: from the full calendar I can read, but the "Events:" from the full calendar doesn’t read, would you tell me why? Main.php $. get("events.json", Function(varEventos){ Events: varEventos } events.json [ { "title":"Jose", "start":"2016-11-01" } ]
– Jose Leandro