github.com/outbrain/consul@v1.4.5/ui-v2/app/utils/injectableRequestToJQueryAjaxHash.js (about) 1 // prettier-ignore 2 /* istanbul ignore file */ 3 export default function(JSON) { 4 // Has to be a property on an object so babel knocks the indentation in 5 return { 6 _requestToJQueryAjaxHash: function(request) { 7 let hash = {}; 8 9 hash.type = request.method; 10 hash.url = request.url; 11 hash.dataType = 'json'; 12 hash.context = this; 13 14 if (request.data) { 15 if (request.method !== 'GET') { 16 hash.contentType = 'application/json; charset=utf-8'; 17 hash.data = JSON.stringify(request.data); 18 } else { 19 hash.data = request.data; 20 } 21 } 22 23 let headers = request.headers; 24 if (headers !== undefined) { 25 hash.beforeSend = function(xhr) { 26 Object.keys(headers).forEach((key) => xhr.setRequestHeader(key, headers[key])); 27 }; 28 } 29 30 return hash; 31 } 32 }._requestToJQueryAjaxHash; 33 }