]> BookStack Code Mirror - bookstack/blobdiff - resources/js/services/http.js
Adds laravel-microscope package
[bookstack] / resources / js / services / http.js
index 5b5e1c4960bd197e9095be6d4346fe2d22256bfd..b05dd23bfd7222834eade6395f655d5916b1b2c1 100644 (file)
@@ -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<Object|String>}
  */
 async function getResponseContent(response) {
+    if (response.status === 204) {
+        return null;
+    }
+
     const responseContentType = response.headers.get('Content-Type');
     const subType = responseContentType.split('/').pop();