richpicking
richpicking

Reputation: 51

Tabulator ajax request and CORS

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' } } });

Upvotes: 2

Views: 1524

Answers (2)

Russ Karlberg
Russ Karlberg

Reputation: 45

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(); });

Upvotes: 0

Oli Folkerd
Oli Folkerd

Reputation: 8348

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

Upvotes: 2

Related Questions