2

I'm having trouble disabling CORS for a tabulator ajax request. Have tried to use values from fetch configuration passed in ajaxConfig but to no avail. If I take out ajaxConfig I get hit with CORS but If I send the ajaxConfig stuff I get an error: load Error - Connection Error: TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body. Code below - thanks for any ideas

var table = new Tabulator("#example-table", { ajaxURL:"https://amz-apigw/xx", ajaxConfig:{ method:"GET", mode: "no-cors", credentials: "omit", headers: { "Content-type": 'application/json; charset=utf-8' } } });

2 Answers2

2

Tabulator uses the standard fetch configuration for CORS, which is disabled by default, there is no need to set the mode, or change any default options as CORS is not used by default.

If you are getting CORS warnings appearing in the console, it is likely that the issue is the server you are requesting data from is on a different domain and is setup to reject cross-origin get requests.

I would suggest checking the configuration of the server first, and having a read of this Fetch API Guide

Oli Folkerd
  • 7,510
  • 1
  • 22
  • 46
  • I manage to get around my CORS issues with Azure by adding `mode: 'no-cors'` into my ajaxConfig – Sean Aug 07 '19 at 15:19
  • Quick update - I think adding `mode: 'no-cors'` may be causing an Ajax load error with an 'opaque' response, so probably not a solution! – Sean Aug 07 '19 at 18:31
  • @oli-folkerd - i am getting a CORS error on one page, trying to access JSON from one address, but trying another JSON request from the same server (IP address) works perfectly. What could the issue be? – kneidels Jul 05 '20 at 13:13
  • That is is the point of CORS, it only kicks in if you are trying to make a get request from a browser from a different origin domain to where the page was loaded from, it is a built in security features of browsers. the server must be configured to accept CORS requests – Oli Folkerd Jul 07 '20 at 21:37
0

I'm having this same exact issue. It was working with Tabulator 3.5, but not with 4.1. I do have the server configured for CORS:

router.use(function (req, res, next) { res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept'); res.header('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE, OPTIONS'); next(); });