Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Allow users to set responseType for XHR requests #6

Merged
merged 1 commit into from
Jun 20, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion polymer-ajax/polymer-xhr.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
makeReadyStateHandler: function(xhr, callback) {
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
callback && callback.call(null, xhr.responseText, xhr);
callback && callback.call(null, xhr.response, xhr);
}
};
},
Expand Down Expand Up @@ -66,6 +66,7 @@
* @param {Object} inOptions.params Data to be sent to the server.
* @param {Object} inOptions.body The content for the request body for POST method.
* @param {Object} inOptions.headers HTTP request headers.
* @param {String} inOptions.responseType The response type. Default is 'text'.
* @param {Object} inOptions.callback Called when request is completed.
* @returns {Object} XHR object.
*/
Expand All @@ -78,6 +79,9 @@
if (params && method == 'GET') {
url += (url.indexOf('?') > 0 ? '&' : '?') + params;
}
if (options.responseType) {
xhr.responseType = options.responseType;
}
xhr.open(method, url, async);
this.makeReadyStateHandler(xhr, options.callback);
this.setRequestHeaders(options.headers);
Expand Down