为什么完整日历无法刷新XML文件中的事件。我将一项添加到XML文件,并且全日历不刷新。任何想法? 它的asp.net和mysql,当我在XML文件中插入一项时,我需要刷新
这是我的代码: 有2个文件asp.net和C# 如果刷新网页,它似乎可以正常工作
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="calendario.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.6.1/fullcalendar.min.css"/>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.12.0/moment.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.6.1/fullcalendar.min.js"></script>
<script>
$(document).ready(function () {
$('#calendar').fullCalendar({
//lang: 'pt',
header: {
left: 'prev,next,today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
eventLimit: true,
businessHours: true,
editable: true,
events: function (start, end, timezone, callback) {
$.ajax({
url: 'eventos_professor.xml',
dataType: 'xml',
data: {
// our hypothetical feed requires UNIX timestamps
start: start.unix(),
end: end.unix()
},
success: function (doc) {
var events = [];
$(doc).find('event').each(function () {
events.push({
title: $(this).attr('title'),
start: $(this).attr('start'), // will be parsed
end: $(this).attr('end'), // will be parsed
textColor: "red",
backgroundColor: "black"
});
});
callback(events);
}
});
},
selectable: true,
dayClick: function (fecha, evento, vista) {
//alert(fecha.format());
$("#myModal").modal();
}
});
$('#calendar').fullCalendar('refetchEvents');
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div class="container">
<div id="calendar">
</div>
</div>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Marcar aula</h4>
<div class="form-group">
<label for="txtData">Data:</label>
<asp:TextBox ID="txtData" runat="server" Enabled="true"></asp:TextBox>
</div>
</div>
<div class="modal-body">
<div class="row" style="background-color:darkgray;">
<div class="form-group">
<label for="DropDownList1">Escolha a Turma:</label>
</div>
<div class="col-xs-4">
<div class="form-group">
<label for="txtHorainicio">Hora início:</label>
<asp:TextBox ID="txtHorainicio" type="Time" CssClass="form-control" runat="server"></asp:TextBox>
</div>
</div>
<div class="col-xs-4">
<div class="form-group">
<label for="txtHorafim">Hora fim:</label>
<asp:TextBox ID="txtHorafim" type="Time" CssClass="form-control" runat="server"></asp:TextBox>
</div>
</div>
<div class="col-xs-4">
<div class="form-group">
<label for="CheckBox1">Repetir Evento</label>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:CheckBox ID="CheckBox1" AutoPostBack="True" runat="server" Checked="false" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</div>
</div>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<div class="row">
<div id="opcoes" runat="server" visible="false">
<div class="col-md-4">
<asp:CheckBox ID="CheckBox2" Text="Registar em Férias" runat="server" />
</div>
<div class="col-md-4">
<asp:CheckBox ID="CheckBox3" Text="Registar em feriados" runat="server" />
</div>
<div class="col-md-4">
<div class="form-group">
<label for="txtDataLimite">Até à data:</label>
<asp:TextBox ID="txtDataLimite" Text="2018-12-31" CssClass="form-control" Enabled="true" runat="server"></asp:TextBox>
</div>
</div>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div class="modal-footer">
<div class="row">
<div class="col-xs-6 text-right">
<asp:Button ID="Button1" class="btn btn-default btn-danger" data-dismiss="modal" runat="server" Text="Close" />
</div>
<div class="col-xs-6 text-left">
<asp:Button ID="Button2" class="btn btn-default btn-success" runat="server" Text="Gravar" OnClick="Add_XML" />
</div>
</div>
</div>
</div>
</div>
</div>
</form>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</body>
</html>
and C# code:
protected void Add_XML(object sender, EventArgs e)
{
XElement xml = XElement.Load("mypath\\eventos_professor.xml");
xml.Add(new XElement("event",
new XAttribute("title", "Agora sim"),
new XAttribute("start", "2018-07-23 19:45:00"),
new XAttribute("end", "2018-07-23 21:45:00")));
xml.Save("mypath\\eventos_professor.xml");
}