X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/d41452f39c90deaca98b4fe0e8c87f7d7aa395b8..refs/pull/2393/head:/resources/js/services/http.js diff --git a/resources/js/services/http.js b/resources/js/services/http.js index 5b5e1c496..b05dd23bf 100644 --- a/resources/js/services/http.js +++ b/resources/js/services/http.js @@ -69,7 +69,10 @@ async function dataRequest(method, url, data = null) { // 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); } @@ -138,10 +141,14 @@ async function request(url, options = {}) { /** * Get the content from a fetch response. * Checks the content-type header to determine the format. - * @param response + * @param {Response} response * @returns {Promise} */ async function getResponseContent(response) { + if (response.status === 204) { + return null; + } + const responseContentType = response.headers.get('Content-Type'); const subType = responseContentType.split('/').pop();