Skip to content
This repository has been archived by the owner on Jun 26, 2022. It is now read-only.

Commit

Permalink
Add support for options.data in utils.ajax type=GET.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Dec 14, 2013
1 parent ff7c60d commit ef396f4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/dom-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,25 @@ utils.ajax = (function() {
if (options.headers == null) options.headers = {};
options.headers['Content-Type'] = options.contentType;
}

// Stringify GET query params.
if (options.type === 'GET' && typeof options.data === 'object') {
var query = '';
var stringifyKeyValuePair = function(key, value) {
return value == null ? '' :
'&' + encodeURIComponent(key) +
'=' + encodeURIComponent(value);
};
for (var key in options.data) {
query += stringifyKeyValuePair(key, options.data[key]);
}

if (query) {
var sep = (options.url.indexOf('?') === -1) ? '?' : '&';
options.url += sep + query.substring(1);
}
}

if (options.credentials) options.withCredentials = true;
xhr.addEventListener('readystatechange', end(xhr, options, deferred));
xhr.open(options.type, options.url, true);
Expand Down

0 comments on commit ef396f4

Please sign in to comment.