From f8ae4195cb259f285ce2546fe4921a470f61b276 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Fri, 16 Oct 2015 18:41:43 +0200 Subject: SONAR-6928 Rewrite the System Info page --- server/sonar-web/src/main/js/helpers/request.js | 28 +++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'server/sonar-web/src/main/js/helpers') diff --git a/server/sonar-web/src/main/js/helpers/request.js b/server/sonar-web/src/main/js/helpers/request.js index 74a5eaaf3bc..00029d3e991 100644 --- a/server/sonar-web/src/main/js/helpers/request.js +++ b/server/sonar-web/src/main/js/helpers/request.js @@ -46,18 +46,23 @@ class Request { submit () { let url = this.url; let options = _.defaults(this.options, OPTIONS); - let headers = _.defaults(this.headers, HEADERS); - options.headers = headers; + options.headers = _.defaults(this.headers, HEADERS); if (this.data) { - if (options.type === 'GET') { + if (options.method === 'GET') { url += '?' + queryString(this.data); } else { + options.headers['Content-Type'] = 'application/x-www-form-urlencoded'; options.body = queryString(this.data); } } return window.fetch(url, options); } + setMethod (method) { + this.options.method = method; + return this; + } + setData (data) { this.data = data; return this; @@ -112,4 +117,19 @@ export function getJSON (url, data) { .submit() .then(checkStatus) .then(parseJSON); -} \ No newline at end of file +} + + +/** + * Shortcut to do a POST request and return response json + * @param url + * @param data + */ +export function postJSON (url, data) { + return request(url) + .setMethod('POST') + .setData(data) + .submit() + .then(checkStatus) + .then(parseJSON); +} -- cgit v1.2.3