Javascript JS,fullcalendar,the;事件“;参数不为';无法获取已执行函数的结果
答:错误不在于同步或异步调用,而在于使用fullcalendar设置的函数。 事件:函数(开始、结束、时区、回调){…} 我可以看到信息切换我如何管理ajax(sjax…)的结果,但日历没有得到信息 “events:getJSON”行似乎不起作用。但是函数是call 现在,我有一个新问题,函数getJSON从webmethod获取JSON,但是日历没有显示它们 我也试图用注释过的代码得到结果,但它不起作用 以下是js中的两种方法:Javascript JS,fullcalendar,the;事件“;参数不为';无法获取已执行函数的结果,javascript,jquery,fullcalendar,jquery-callback,Javascript,Jquery,Fullcalendar,Jquery Callback,答:错误不在于同步或异步调用,而在于使用fullcalendar设置的函数。 事件:函数(开始、结束、时区、回调){…} 我可以看到信息切换我如何管理ajax(sjax…)的结果,但日历没有得到信息 “events:getJSON”行似乎不起作用。但是函数是call 现在,我有一个新问题,函数getJSON从webmethod获取JSON,但是日历没有显示它们 我也试图用注释过的代码得到结果,但它不起作用 以下是js中的两种方法: function getJSON() { start =
function getJSON() {
start = $('#calendar').fullCalendar('getDate').format();
duration = $('#calendar').fullCalendar('getCalendar').moment().format();
alert(start);
var retour;
$.ajax({
async: false,
type: 'POST',
url: "ConsultationPlanning.aspx/getPlanning",
data: '{"start": "' + start + '", "end": "' + duration + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
retour = JSON.parse(msg.d);
retour = msg.d;
},
error: function () { alert("erreur");}
});
alert(retour);
return retour;
};
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
hiddenDays: [0],
defaultView: 'agendaWeek',
editable: false,
allDaySlot: false,
selectable: false,
events: getJSON,
/*function (start, end, callback) {
start = $('#calendar').fullCalendar('getDate').format();
duration = $('#calendar').fullCalendar('getCalendar').moment().format();
$.ajax({
type: 'POST',
url: "ConsultationPlanning.aspx/getPlanning",
data: '{"start": "' + start + '", "end": "' + end + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
var rdv = [];
alert(msg.d);
//var events =JSON.parse(msg.d);
$(msg.d).each(function () {
rdv.push({
id: $(this).attr('id'),
title: $(this).attr('title'),
start: $(this).attr('start'),
})
})
alert("first date : " + rdv[0].start);
//"first date: 2015-05-06T14:33:00" is what i get
callback(rdv);
//the callback generate an error message. it says, it's waiting for a function
}
})
}
});
几天前,我发布了一个类似的问题,但它与另一个实现有关:
$。ajax
触发异步调用;只有在浏览器收到请求响应后,retour
变量的值才会设置为您期望的值
这就是为什么fullcalendar的事件
使用回调
参数调用的原因:
function getJSON(start, end, callback) {
...
$.ajax({
...
success : function(msg) {
retour = JSON.parse(msg.d);
callback(retour);
}
});
// no need to return anything here
}
请参阅fullcalendar v1的文档。*此处:
注意:如果您使用的是fullcalendar v2或更高版本,则应将函数签名更改为:
function getJSON(start, end, timezone, callback) {
...
请参阅v2的文档。*此处:它将起作用,请参考我在这个问题中的答案将其称为函数事件:getJSON()当我用括号调用函数时,我不能在函数getJSON中使用“$('#calendar').fullCalendar('getDate').format();”非常感谢您,我正在使用fullcalendar v2,我想我可以在没有时区的情况下运行该函数。我只是添加了参数,没有使用它,它就工作了。如果可以的话,我点击箭头说你的答案对我有用。此外,我还取消了代码注释并删除了函数getJSON