Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 022fc44

Browse files
SQUASH ME: feat($http): specify the JSONP callback via the jsonpCallbackParam config value
1 parent 9be46a7 commit 022fc44

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

docs/content/error/$http/badjsonp.ngdoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
@fullName Bad JSONP Request Configuration
44
@description
55

6-
This error occurs when the URL generated from the configuration object contains a parameter with the same name as the configured `callbackParam`
6+
This error occurs when the URL generated from the configuration object contains a parameter with the same name as the configured `jsonpCallbackParam`
77
property; or when it contains a parameter whose value is `JSON_CALLBACK`.
88

99
`$http` JSON requests need to attach a callback query parameter to the URL. The name of this parameter is specified in the configuration
10-
object (or in the defaults) via the `callbackParam` property. You must not provide your own parameter with this name in the configuration
10+
object (or in the defaults) via the `jsonpCallbackParam` property. You must not provide your own parameter with this name in the configuration
1111
of the request.
1212

1313
In previous versions of Angular, you specified where to add the callback parameter value via the `JSON_CALLBACK` placeholder. This is no longer
1414
allowed.
1515

16-
To resolve this error, remove any parameters that have the same name as the `callbackParam`; and/or remove any parameters that have a value of `JSON_CALLBACK`.
16+
To resolve this error, remove any parameters that have the same name as the `jsonpCallbackParam`; and/or remove any parameters that have a value of `JSON_CALLBACK`.
1717

1818
For more information, see the {@link ng.$http#jsonp `$http.jsonp()`} method API documentation.

src/ng/http.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ function $HttpProvider() {
286286
* If specified as string, it is interpreted as a function registered with the {@link auto.$injector $injector}.
287287
* Defaults to {@link ng.$httpParamSerializer $httpParamSerializer}.
288288
*
289-
* - **`defaults.callbackParam`** - `{string} - the name of the query parameter that passes the callback in a JSONP
289+
* - **`defaults.jsonpCallbackParam`** - `{string} - the name of the query parameter that passes the callback in a JSONP
290290
* request. The value of this parameter will be replaced with the expression generated by the {@link jsonpCallbacks}
291291
* service. Defaults to `'callback'`.
292292
*
@@ -315,7 +315,7 @@ function $HttpProvider() {
315315

316316
paramSerializer: '$httpParamSerializer',
317317

318-
callbackParam: 'callback'
318+
jsonpCallbackParam: 'callback'
319319
};
320320

321321
var useApplyAsync = false;
@@ -971,7 +971,7 @@ function $HttpProvider() {
971971
transformRequest: defaults.transformRequest,
972972
transformResponse: defaults.transformResponse,
973973
paramSerializer: defaults.paramSerializer,
974-
callbackParam: defaults.callbackParam
974+
jsonpCallbackParam: defaults.jsonpCallbackParam
975975
}, requestConfig);
976976

977977
config.headers = mergeHeaders(requestConfig);
@@ -1177,13 +1177,13 @@ function $HttpProvider() {
11771177
*
11781178
* JSONP requests must specify a callback to be used in the response from the server. This callback
11791179
* is passed as as a query parameter in the request. You must specify the name of this parameter by
1180-
* setting the `callbackParam` property on the request config object.
1180+
* setting the `jsonpCallbackParam` property on the request config object.
11811181
*
11821182
* ```
1183-
* $http.jsonp('some/trusted/url', {callbackParam: 'callback'})
1183+
* $http.jsonp('some/trusted/url', {jsonpCallbackParam: 'callback'})
11841184
* ```
11851185
*
1186-
* You can also specify a global callback parameter key in `$http.defaults.callbackParam`.
1186+
* You can also specify a global callback parameter key in `$http.defaults.jsonpCallbackParam`.
11871187
* By default this is set to `callback`.
11881188
*
11891189
* <div class="alert alert-danger">
@@ -1310,7 +1310,7 @@ function $HttpProvider() {
13101310

13111311
if (isJsonp) {
13121312
// Check the url and add the JSONP callback placeholder
1313-
url = sanitizeJsonpCallbackParam(url, config.callbackParam);
1313+
url = sanitizeJsonpCallbackParam(url, config.jsonpCallbackParam);
13141314
}
13151315

13161316
$http.pendingRequests.push(config);

test/ng/httpSpec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1091,15 +1091,15 @@ describe('$http', function() {
10911091
expect(error.message).toContain('[$http:badjsonp]');
10921092
});
10931093

1094-
it('should error if there is already a param matching the callbackParam key', function() {
1094+
it('should error if there is already a param matching the jsonpCallbackParam key', function() {
10951095
var error;
10961096
$http({ method: 'JSONP', url: $sce.trustAsResourceUrl('http://example.org/path'), params: {callback: 'evilThing'}})
10971097
.catch(function(e) { error = e; });
10981098
$rootScope.$digest();
10991099
expect(error.message).toContain('[$http:badjsonp]');
11001100

11011101
error = undefined;
1102-
$http({ method: 'JSONP', callbackParam: 'cb', url: $sce.trustAsResourceUrl('http://example.org/path'), params: {cb: 'evilThing'}})
1102+
$http({ method: 'JSONP', jsonpCallbackParam: 'cb', url: $sce.trustAsResourceUrl('http://example.org/path'), params: {cb: 'evilThing'}})
11031103
.catch(function(e) { error = e; });
11041104
$rootScope.$digest();
11051105
expect(error.message).toContain('[$http:badjsonp]');

0 commit comments

Comments
 (0)