JEB JEB - 2 months ago 32x
React JSX Question

How to make a POST request with json content type with Semantic UI API

I am using the API feature of dropdowns with Semantic UI and want to do a POST request on my API to search for users

By default the API feature of Semantic UI sends form-data content type.

To force the right content-type, I did something like :

apiSettings: {
url: '/api/search/',
method: 'POST',
beforeXHR: (xhr) => {
xhr.setRequestHeader('Content-Type', 'application/json');
beforeSend: (settings) => { = {
type: 'user',
query: 'test'
return settings

but data is still sent in a form-data fashion, like
instead of a real JSON object payload like
{type: 'user', query: 'test'}

How can I send a json object with Semantic UI API to my own POST API route ?


Use JSON.stringify:

JSON.stringify({type: 'user', query: 'test'})