Sending JSON with data Javascript Fetch

An important reminder to include following header while sending data in Javascript fetch() call in JSON format.

Also, do not forget to use JSON.Stringify().

var data = { some_data: ABC};
headers: {
    'Content-Type': 'application/json',
body: JSON.stringify( data ),

This is not needed if you are creating a form data object and appending data to it.

var data = new FormData();
data.append( 'some_data', 'ABC' );

By Abhineet Mittal

Abhineet is IIM Alumnus and Founder of popular Digital Publishing Platform, Sahityapedia. He is a technology enthusiast by hobby & an avid reader.