From 1fc3d6230cc1afbfd537b9c518b36959a110db1a Mon Sep 17 00:00:00 2001 From: Sefa Ilkimen Date: Fri, 14 Jun 2019 00:52:27 +0200 Subject: [PATCH] - update readme - implement response type support for browser platform --- README.md | 3 +++ src/browser/cordova-http-plugin.js | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 91231be..6364ec4 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,9 @@ The options object contains following keys: * `data`: payload to be send to the server (only applicable on `post`, `put` or `patch` methods) * `params`: query params to be appended to the URL (only applicable on `get`, `head`, `delete`, `upload` or `download` methods) * `serializer`: data serializer to be used (only applicable on `post`, `put` or `patch` methods), defaults to global serializer value, see [setDataSerializer](#setDataSerializer) for supported values +* `responseType`: expected response type, defaults to `text`, needs to be one of the following values: + * `text` use this for all kind of text responses (e.g. JSON, XML, HTML, plain text, etc.) + * `arraybuffer` use this one for binary responses * `timeout`: timeout value for the request in seconds, defaults to global timeout value * `followRedirect`: enable or disable automatically following redirects * `headers`: headers object (key value pair), will be merged with global values diff --git a/src/browser/cordova-http-plugin.js b/src/browser/cordova-http-plugin.js index 17ad71b..670c49a 100644 --- a/src/browser/cordova-http-plugin.js +++ b/src/browser/cordova-http-plugin.js @@ -101,7 +101,7 @@ function setHeaders(xhr, headers) { } function sendRequest(method, withData, opts, success, failure) { - var data, serializer, headers, timeout, followRedirect; + var data, serializer, headers, timeout, followRedirect, responseType; var url = opts[0]; if (withData) { @@ -110,10 +110,13 @@ function sendRequest(method, withData, opts, success, failure) { headers = opts[3]; timeout = opts[4]; followRedirect = opts[5]; + responseType = opts[6]; } else { headers = opts[1]; timeout = opts[2]; followRedirect = opts[3]; + responseType = opts[4]; + } var processedData = null; @@ -152,6 +155,7 @@ function sendRequest(method, withData, opts, success, failure) { } xhr.timeout = timeout * 1000; + xhr.responseType = responseType; setHeaders(xhr, headers); xhr.onerror = xhr.ontimeout = function () {