Hello, good afternoon, classmates, I have a problem with my ajax code, what happens is that when calling my function drawnCalendar () since c # executes well, it even enters the function's success but I can not make it paint fullcalendar the weird thing is that he paints it only once when he starts the page I know that success works because I have sent alerts and shows them without inconvenience.
<%@ Page Title="Kardex" Language="C#" MasterPageFile="~/Master.master" AutoEventWireup="true" CodeFile="Kardex.aspx.cs" Inherits="Kardex" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript" src="scripts/alertify.js"></script>
<link rel="stylesheet" href="css/alertify.core.css" />
<link rel="stylesheet" href="css/alertify.default.css" />
<link rel="stylesheet" href="css/estilos.css" />
<link rel="Stylesheet" href="plugins/ui/jquery-ui.css" />
<link rel="stylesheet" href="plugins/fullcalendar/fullcalendar.min.css"/>
<script type="text/javascript" src="plugins/ui/jquery-1.9.1.js"></script>
<script type="text/javascript" src="plugins/ui/jquery-ui.js"></script>
<script type="text/javascript" src="plugins/fullcalendar/moment.js"></script>
<script type="text/javascript" src="plugins/fullcalendar/fullcalendar.min.js"></script>
<style type="text/css">
table select { font-size:11px !important; padding:0 !important }
table {font-size:11.5px}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <section class="content-header">
<h1>
Empleado
</h1>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<!-- left column -->
<div class="col-md-12">
<!-- general form elements -->
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">Kardex Empleados</h3>
<div class="pull-right">
<asp:Label ID="lblTotal" runat="server" Font-Bold="true"></asp:Label>
</div><!-- /.pull-right -->
</div><!-- /.box-header -->
<!-- form start -->
<div class="box-body">
<div class="row">
<div class="col-md-2">
<div class="form-group">
<label for="exampleInputEmail1">Número de Empleado</label>
<asp:TextBox ID="txtNumEmpleado" runat="server" CssClass="form-control" MaxLength="5"
AutoComplete="off"
AutoPostBack="true" >
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="(*) Campo Requerido"
ForeColor="Red" ControlToValidate="txtNumEmpleado" ValidationGroup="vg_reporte">
</asp:RequiredFieldValidator>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<br />
<asp:Button ID="btnBuscar" runat="server" Text="Buscar"
CssClass="btn btn-primary" ValidationGroup="vg_reporte" onclick="btnBuscar_Click"
></asp:Button>
</div>
</div>
<div class="col-md-3 pull-right">
<asp:LinkButton ID="btnExcel" runat="server" CssClass="btn btn-success" >
<i class="fa fa-file-excel-o"></i> Descarga Excel
</asp:LinkButton>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div id="calendar">
</div>
<div class="box-body table-responsive no-padding">
<asp:GridView ID="gvKardex" runat="server" CssClass="table table-bordered table-striped" GridLines="None"
EmptyDataText="Sin información"
>
</asp:GridView>
</div>
</div>
</div>
</div><!-- /.box-body -->
<div class="box-footer">
</div>
</div><!-- /.box -->
</div>
</div>
</section>
<script>
//AJAX
function drawCalendar() {
$.ajax({
type: "POST",
contentType: "application/json",
data: "{}",
url: "Kardex.aspx/MyMethod",
dataType: "json",
async: "true",
cache: "false",
success: function (data) {
//eventos = data.d;
//alert(JSON.stringify(data.d));
//drawCalendar(data.d);
$('div[id*=calendar]').fullCalendar({
header: {
left: 'prev,next today',
/*left : '',*/
center: 'title',
/*right: ''*/
right: 'month,agendaWeek,agendaDay'
},
editable: true,
events: $.map(data.d, function (item, i) {
var event = new Object();
event.start = item.start;
event.title = item.title;
return event;
}),
loading: function (bool) {
if (bool) $('.loading').show();
else $('.loading').hide();
}
});
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
debugger;
alert("ERROR: " + JSON.stringify(XMLHttpRequest));
}
});
}
</script>
</asp:Content>
My code in C #
static IList events = new List<Event>();
protected void btnBuscar_Click(object sender, EventArgs e)
{
buscar();
}
public void buscar()
{
try
{
//Ejecuto Procedimiento Almacenado
while (lector.Read() == true)
{
if (lector["Concepto 1"].ToString() != "")
{
events.Add(new Event
{
title = lector["Concepto 1"].ToString(),
start = lector["Fecha"].ToString(),
backgroundColor = "#f56954",
borderColor = "#f56954"
});
}
}
con.Close();
}
catch (Exception ex)
{
excepciones(ex.Message.ToString());
}
}
[WebMethod]
public static IList MyMethod()
{
try
{
//Do here server event
IList eventos = new List<Event>();
eventos = events;
return events;
}
catch (Exception)
{
throw;
}
}