0

I need to send to the servlet all events stored in the 'fullcallendar memory'. I know yet that fullcalendar has a callback that returns the array of all events:

$(#calendar).fullcalendar('clientEvents') -> Array[]

And I'm using a normal AJAX post to the servlet to send this array, for example:

var events = new Array();
events = JSON.stringify($(#calendar).fullcalendar('clientEvents'));
$.ajax(
        {
         async: false,
         url: 'SaverServlet',
         type: 'POST',
         data: "eventsParameter="+events,
         processData: false,
         dataType: "json",
         success: function () {
                alert("ajax success");
         },
         error: function () {
                debugger;
                alert("ajax failure");
         }

});

But all this miserably fails. I tried many ways without success. I think that the problem is the JSON.stringify(). I tried also to do this:

var events = new Array();
    events = $(#calendar).fullcalendar('clientEvents');
    $.ajax(
            {
             async: false,
             url: 'SaverServlet',
             type: 'POST',
             data: "eventsParameter="+events,
             processData: false,
             dataType: "json",
             success: function () {
                    alert("ajax success");
             },
             error: function () {
                    debugger;
                    alert("ajax failure");
             }

});

But this all fails, the array reaches successfully the servlets but it seems to be unreadable or un unpareseable in JSON sense. Can someone help me?

shogitai
  • 1,823
  • 1
  • 23
  • 50
  • Is the error occurring in your Java servlet or in the JavaScript? Can you post the error? – blacktide Apr 03 '16 at 21:15
  • The only feedback that I see is that I don't see both alerts in the ajax. Meanwhile I remove the JSON.stringfy() all works 'correctly'. Not a servlet problem surely. – shogitai Apr 03 '16 at 21:18
  • 1
    In hindsight, this is a better duplicate: http://stackoverflow.com/questions/30150148/request-getparameter-returns-null-when-using-ajax-with-json-object-as-data/ Nonetheless, hopefully both are helpful. – BalusC Apr 03 '16 at 21:28
  • Thank you, but I have seen yet these "duplicates" and they didn't help me. The problem is passing from var myArray = $(#calendar).fullcalendar('clientEvents') to JSON.stringify(myArray), I am 80% sure that this is the problem or near this operation. – shogitai Apr 04 '16 at 06:29

0 Answers0