From 42a3af2e382cb967a1361dbeb11c320d0c8adc61 Mon Sep 17 00:00:00 2001 From: Pooya Paridel Date: Tue, 3 May 2016 12:59:11 -0700 Subject: [PATCH 1/2] Sending data as JSON if content type is application/json Instead of encoding data, if content type is application/json then data will be send as stringify JSON data. --- promise.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/promise.js b/promise.js index 2097271..70f99bb 100644 --- a/promise.js +++ b/promise.js @@ -128,14 +128,6 @@ return p; } - payload = _encode(data); - if (method === 'GET' && payload) { - url += '?' + payload; - payload = null; - } - - xhr.open(method, url); - var content_type = 'application/x-www-form-urlencoded'; for (var h in headers) { if (headers.hasOwnProperty(h)) { @@ -147,6 +139,17 @@ } xhr.setRequestHeader('Content-type', content_type); + payload = _encode(data); + if (method === 'GET' && payload) { + url += '?' + payload; + payload = null; + } + else if (content_type==="application/json") + { + payload = JSON.stringify(data) + } + + xhr.open(method, url); function onTimeout() { xhr.abort(); From 599376faa9c6b8752284dc3d323da5666d106a9b Mon Sep 17 00:00:00 2001 From: Pooya Paridel Date: Tue, 3 May 2016 13:06:16 -0700 Subject: [PATCH 2/2] Update promise.js --- promise.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/promise.js b/promise.js index 70f99bb..7fb7382 100644 --- a/promise.js +++ b/promise.js @@ -128,6 +128,14 @@ return p; } + payload = _encode(data); + if (method === 'GET' && payload) { + url += '?' + payload; + payload = null; + } + + xhr.open(method, url); + var content_type = 'application/x-www-form-urlencoded'; for (var h in headers) { if (headers.hasOwnProperty(h)) { @@ -139,18 +147,11 @@ } xhr.setRequestHeader('Content-type', content_type); - payload = _encode(data); - if (method === 'GET' && payload) { - url += '?' + payload; - payload = null; - } - else if (content_type==="application/json") + if (content_type==="application/json") { payload = JSON.stringify(data) } - xhr.open(method, url); - function onTimeout() { xhr.abort(); p.done(promise.ETIMEOUT, "", xhr);