vkurko / calendar

Full-sized drag & drop JavaScript event calendar with resource & timeline views
https://vkurko.github.io/calendar/
MIT License
964 stars 82 forks source link

Unable to pass "headers" in EventSource POST #228

Closed oldmanwerther closed 4 months ago

oldmanwerther commented 4 months ago

When configuring to POST into my endpoint, it seems as if I can't add headers as a nested object in extraParams. The rendered payload shows as [object Object].

my js:

...
        eventSources: [
            {
                url: "https://localhost:44336/GetProducts",
                method: "POST",
                extraParams: {
                    mode: "cors",
                    referrerPolicy: "no-referrer",
                    headers: {
                        "Content-Type": "application/json",
                        "Accept": 'application/json'
                    },
                    body: bodyRequest
                }
            }
        ],...
vkurko commented 4 months ago

The extraParams option is intended only for additional parameters, not headers. Unfortunately there is no option for headers, but you can implement your own HTTP request via eventSource as a function.

oldmanwerther commented 4 months ago

Yes, that worked. Thanks. Posting my modified code for anyone else:

eventSources: [
         {
             events: function (fetchInfo, successCallback, failureCallback) { 

                 fetch(apiEndpointUrl,
                     {
                         method: "POST",
                         mode: "cors",
                         headers: {
                             "Content-Type": "application/json",
                             "Access-Control-Allow-Origin": "*"
                         },
                         referrerPolicy: "no-referrer",
                         body: bodyRequest
                     }).then(res => {
                         return res.json();
                     }).then(res => {
                         successCallback(res);
                     });
             }

         }
     ]
vkurko commented 4 months ago

Great!