fix($browser.xhr): change method "JSON" to "JSONP"

Breaks "JSON" xhr method is now called "JSONP"
This commit is contained in:
Vojta Jina 2011-08-10 15:59:55 +02:00 committed by Igor Minar
parent 0c8b35681e
commit 45f47ff6cd
5 changed files with 14 additions and 14 deletions

View file

@ -18,8 +18,8 @@ to retrieve Buzz activity and comments.
this.Activity = $resource( this.Activity = $resource(
'https://www.googleapis.com/buzz/v1/activities/:userId/:visibility/:activityId/:comments', 'https://www.googleapis.com/buzz/v1/activities/:userId/:visibility/:activityId/:comments',
{alt: 'json', callback: 'JSON_CALLBACK'}, {alt: 'json', callback: 'JSON_CALLBACK'},
{ get: {method: 'JSON', params: {visibility: '@self'}}, { get: {method: 'JSONP', params: {visibility: '@self'}},
replies: {method: 'JSON', params: {visibility: '@self', comments: '@comments'}} replies: {method: 'JSONP', params: {visibility: '@self', comments: '@comments'}}
}); });
} }
BuzzController.prototype = { BuzzController.prototype = {

View file

@ -99,7 +99,7 @@ function Browser(window, document, body, XHR, $log, $sniffer) {
*/ */
self.xhr = function(method, url, post, callback, headers) { self.xhr = function(method, url, post, callback, headers) {
outstandingRequestCount ++; outstandingRequestCount ++;
if (lowercase(method) == 'json') { if (lowercase(method) == 'jsonp') {
var callbackId = ("angular_" + Math.random() + '_' + (idCounter++)).replace(/\d\./, ''); var callbackId = ("angular_" + Math.random() + '_' + (idCounter++)).replace(/\d\./, '');
window[callbackId] = function(data) { window[callbackId] = function(data) {
window[callbackId].data = data; window[callbackId].data = data;

View file

@ -40,7 +40,7 @@
* - `action` {string} The name of action. This name becomes the name of the method on your * - `action` {string} The name of action. This name becomes the name of the method on your
* resource object. * resource object.
* - `method` {string} HTTP request method. Valid methods are: `GET`, `POST`, `PUT`, `DELETE`, * - `method` {string} HTTP request method. Valid methods are: `GET`, `POST`, `PUT`, `DELETE`,
* and `JSON` (also known as JSONP). * and `JSONP`
* - `params` {object=} Optional set of pre-bound parameters for this action. * - `params` {object=} Optional set of pre-bound parameters for this action.
* - isArray {boolean=} If true then the returned object for this action is an array, see * - isArray {boolean=} If true then the returned object for this action is an array, see
* `returns` section. * `returns` section.
@ -163,7 +163,7 @@
this.Activity = $resource( this.Activity = $resource(
'https://www.googleapis.com/buzz/v1/activities/:userId/:visibility/:activityId/:comments', 'https://www.googleapis.com/buzz/v1/activities/:userId/:visibility/:activityId/:comments',
{alt:'json', callback:'JSON_CALLBACK'}, {alt:'json', callback:'JSON_CALLBACK'},
{get:{method:'JSON', params:{visibility:'@self'}}, replies: {method:'JSON', params:{visibility:'@self', comments:'@comments'}}} {get:{method:'JSONP', params:{visibility:'@self'}}, replies: {method:'JSONP', params:{visibility:'@self', comments:'@comments'}}}
); );
} }

View file

@ -85,7 +85,7 @@
* {@link http://en.wikipedia.org/wiki/Rainbow_table salt for added security}. * {@link http://en.wikipedia.org/wiki/Rainbow_table salt for added security}.
* *
* @param {string} method HTTP method to use. Valid values are: `GET`, `POST`, `PUT`, `DELETE`, and * @param {string} method HTTP method to use. Valid values are: `GET`, `POST`, `PUT`, `DELETE`, and
* `JSON`. `JSON` is a special case which causes a * `JSONP`. `JSONP` is a special case which causes a
* [JSONP](http://en.wikipedia.org/wiki/JSON#JSONP) cross domain request using script tag * [JSONP](http://en.wikipedia.org/wiki/JSON#JSONP) cross domain request using script tag
* insertion. * insertion.
* @param {string} url Relative or absolute URL specifying the destination of the request. For * @param {string} url Relative or absolute URL specifying the destination of the request. For
@ -135,13 +135,13 @@
<div ng:controller="FetchCntl"> <div ng:controller="FetchCntl">
<select ng:model="method"> <select ng:model="method">
<option>GET</option> <option>GET</option>
<option>JSON</option> <option>JSONP</option>
</select> </select>
<input type="text" ng:model="url" size="80"/> <input type="text" ng:model="url" size="80"/>
<button ng:click="fetch()">fetch</button><br> <button ng:click="fetch()">fetch</button><br>
<button ng:click="updateModel('GET', 'index.html')">Sample GET</button> <button ng:click="updateModel('GET', 'index.html')">Sample GET</button>
<button ng:click="updateModel('JSON', 'http://angularjs.org/greet.php?callback=JSON_CALLBACK&name=Super%20Hero')">Sample JSONP</button> <button ng:click="updateModel('JSONP', 'http://angularjs.org/greet.php?callback=JSON_CALLBACK&name=Super%20Hero')">Sample JSONP</button>
<button ng:click="updateModel('JSON', 'http://angularjs.org/doesntexist&callback=JSON_CALLBACK')">Invalid JSONP</button> <button ng:click="updateModel('JSONP', 'http://angularjs.org/doesntexist&callback=JSON_CALLBACK')">Invalid JSONP</button>
<pre>code={{code}}</pre> <pre>code={{code}}</pre>
<pre>response={{response}}</pre> <pre>response={{response}}</pre>
</div> </div>

View file

@ -111,7 +111,7 @@ describe('browser', function() {
}); });
describe('xhr', function() { describe('xhr', function() {
describe('JSON', function() { describe('JSONP', function() {
var log; var log;
function callback(code, data) { function callback(code, data) {
@ -129,7 +129,7 @@ describe('browser', function() {
it('should add script tag for JSONP request', function() { it('should add script tag for JSONP request', function() {
var notify = jasmine.createSpy('notify'); var notify = jasmine.createSpy('notify');
browser.xhr('JSON', 'http://example.org/path?cb=JSON_CALLBACK', null, callback); browser.xhr('JSONP', 'http://example.org/path?cb=JSON_CALLBACK', null, callback);
browser.notifyWhenNoOutstandingRequests(notify); browser.notifyWhenNoOutstandingRequests(notify);
expect(notify).not.toHaveBeenCalled(); expect(notify).not.toHaveBeenCalled();
expect(scripts.length).toEqual(1); expect(scripts.length).toEqual(1);
@ -148,7 +148,7 @@ describe('browser', function() {
it('should call callback when script fails to load', function() { it('should call callback when script fails to load', function() {
browser.xhr('JSON', 'http://example.org/path?cb=JSON_CALLBACK', null, callback); browser.xhr('JSONP', 'http://example.org/path?cb=JSON_CALLBACK', null, callback);
var script = scripts[0]; var script = scripts[0];
expect(typeof script.onload).toBe('function'); expect(typeof script.onload).toBe('function');
expect(typeof script.onerror).toBe('function'); expect(typeof script.onerror).toBe('function');
@ -160,7 +160,7 @@ describe('browser', function() {
it('should update the outstandingRequests counter for successful requests', function() { it('should update the outstandingRequests counter for successful requests', function() {
var notify = jasmine.createSpy('notify'); var notify = jasmine.createSpy('notify');
browser.xhr('JSON', 'http://example.org/path?cb=JSON_CALLBACK', null, callback); browser.xhr('JSONP', 'http://example.org/path?cb=JSON_CALLBACK', null, callback);
browser.notifyWhenNoOutstandingRequests(notify); browser.notifyWhenNoOutstandingRequests(notify);
expect(notify).not.toHaveBeenCalled(); expect(notify).not.toHaveBeenCalled();
@ -175,7 +175,7 @@ describe('browser', function() {
it('should update the outstandingRequests counter for failed requests', function() { it('should update the outstandingRequests counter for failed requests', function() {
var notify = jasmine.createSpy('notify'); var notify = jasmine.createSpy('notify');
browser.xhr('JSON', 'http://example.org/path?cb=JSON_CALLBACK', null, callback); browser.xhr('JSONP', 'http://example.org/path?cb=JSON_CALLBACK', null, callback);
browser.notifyWhenNoOutstandingRequests(notify); browser.notifyWhenNoOutstandingRequests(notify);
expect(notify).not.toHaveBeenCalled(); expect(notify).not.toHaveBeenCalled();