diff --git a/src/ng/http.js b/src/ng/http.js index 61c7e8bae6cf..25b4801d6aca 100644 --- a/src/ng/http.js +++ b/src/ng/http.js @@ -117,7 +117,9 @@ function $HttpProvider() { }, xsrfCookieName: 'XSRF-TOKEN', - xsrfHeaderName: 'X-XSRF-TOKEN' + xsrfHeaderName: 'X-XSRF-TOKEN', + + useArrayParams: false }; /** @@ -485,6 +487,7 @@ function $HttpProvider() { * for more information. * - **responseType** - `{string}` - see * [requestType](https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#responseType). + * - **useArrayParams** - `{boolean}` - true if arrays should be sent as `param[]=val1¶m[]=val2` instead of `param=val1¶m=val2`. * * @returns {HttpPromise} Returns a {@link ng.$q promise} object with the * standard `then` method and two http specific methods: `success` and `error`. The `then` @@ -594,7 +597,8 @@ function $HttpProvider() { var config = { method: 'get', transformRequest: defaults.transformRequest, - transformResponse: defaults.transformResponse + transformResponse: defaults.transformResponse, + useArrayParams: defaults.useArrayParams }; var headers = mergeHeaders(requestConfig); @@ -852,7 +856,7 @@ function $HttpProvider() { promise = deferred.promise, cache, cachedResp, - url = buildUrl(config.url, config.params); + url = buildUrl(config.url, config.params, config.useArrayParams); $http.pendingRequests.push(config); promise.then(removePendingReq, removePendingReq); @@ -939,18 +943,19 @@ function $HttpProvider() { } - function buildUrl(url, params) { + function buildUrl(url, params, useArrayParams) { if (!params) return url; var parts = []; forEachSorted(params, function(value, key) { if (value === null || isUndefined(value)) return; - if (!isArray(value)) value = [value]; + var valueIsArray = isArray(value); + if (!valueIsArray) value = [value]; forEach(value, function(v) { if (isObject(v)) { v = toJson(v); } - parts.push(encodeUriQuery(key) + '=' + + parts.push(encodeUriQuery(key) + (valueIsArray && useArrayParams ? '[]' : '') + '=' + encodeUriQuery(v)); }); });
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: