// Send data as JSON if a plain object
if (typeof data === 'object' && !(data instanceof FormData)) {
- options.headers = {'Content-Type': 'application/json'};
+ options.headers = {
+ 'Content-Type': 'application/json',
+ 'X-Requested-With': 'XMLHttpRequest',
+ };
options.body = JSON.stringify(data);
}
/**
* Get the content from a fetch response.
* Checks the content-type header to determine the format.
- * @param response
+ * @param {Response} response
* @returns {Promise<Object|String>}
*/
async function getResponseContent(response) {
+ if (response.status === 204) {
+ return null;
+ }
+
const responseContentType = response.headers.get('Content-Type');
const subType = responseContentType.split('/').pop();