skip to Main Content

enter image description herePlease anyone can help me to solve this issue?
I have been trying to solve this issue for 3 days, and jquery Ajax is new to me.

I want to bind live data with the calendar in asp.net core 6.0 using jquery Ajax.
I got the data from the database in success result of jquery Ajax.

I got an error when I try to push data inside the array, which comes from the database.
When I am trying to push data in an array I got undefined inside the array.
I don’t know where I did the mistake.

$(document).ready(function() {
  debugger
  $.ajax({
    type: "GET",
    url: "/Admin/Calendar/GetBookings",
    dataType: "JSON",
    success: function(result) {
      debugger
      var Booking = [];
      $.each(result, function(i, data) {
        Booking.push({
          title: data.title,
          description: data.description,
          start: data.startDate,
          end: data.endDate
        });
      });
      GenerateCalendar(Booking);
    },
    error: function(error) {
      alert('failed');
    }
  });
  function GenerateCalendar(Booking) {
    debugger
    $('#calendar').fullCalendar({
      header: {
        left: 'prev,next,today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
      }
    })
  }
});

2

Answers


  1. The result is not an array but an object containing an array.

    Instead of:
    $.each(result, function(i, data)

    you should use:
    $.each(result.data, function(i, data)

    Login or Signup to reply.
  2. Assuming you have result.data as an array, you can do

    const Booking = result.data
      .map(({title,description,startDate,endDate}) => ({ title, description, start:startDate, end: endDate });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search