mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
Remove the script tag after successful JSONP request
This commit is contained in:
parent
c578f8c3ed
commit
0084cb5ca4
3 changed files with 11 additions and 7 deletions
|
|
@ -8,6 +8,7 @@
|
|||
### Bug Fixes
|
||||
- Fixed cookies which contained unescaped '=' would not show up in cookie service.
|
||||
- Consider all 2xx responses as OK, not just 200
|
||||
- Remove the script tag after successful JSONP request
|
||||
|
||||
### Breaking changes
|
||||
- Changed the $browser.xhr parameter post from optional to required. Since everyone should be
|
||||
|
|
|
|||
|
|
@ -91,13 +91,12 @@ function Browser(window, document, body, XHR, $log) {
|
|||
self.xhr = function(method, url, post, callback, headers) {
|
||||
outstandingRequestCount ++;
|
||||
if (lowercase(method) == 'json') {
|
||||
var callbackId = "angular_" + Math.random() + '_' + (idCounter++);
|
||||
callbackId = callbackId.replace(/\d\./, '');
|
||||
var script = document[0].createElement('script');
|
||||
script.type = 'text/javascript';
|
||||
script.src = url.replace('JSON_CALLBACK', callbackId);
|
||||
var callbackId = ("angular_" + Math.random() + '_' + (idCounter++)).replace(/\d\./, '');
|
||||
var script = jqLite('<script>')
|
||||
.attr({type: 'text/javascript', src: url.replace('JSON_CALLBACK', callbackId)});
|
||||
window[callbackId] = function(data){
|
||||
window[callbackId] = _undefined;
|
||||
script.remove();
|
||||
completeOutstandingRequest(callback, 200, data);
|
||||
};
|
||||
body.append(script);
|
||||
|
|
|
|||
|
|
@ -85,12 +85,16 @@ describe('browser', function(){
|
|||
browser.notifyWhenNoOutstandingRequests(callback);
|
||||
expect(callback).not.wasCalled();
|
||||
expect(scripts.length).toEqual(1);
|
||||
var url = scripts[0].src.split('?cb=');
|
||||
var script = scripts[0];
|
||||
script.remove = function(){
|
||||
log += 'remove();';
|
||||
};
|
||||
var url = script.attr('src').split('?cb=');
|
||||
expect(url[0]).toEqual('http://example.org/path');
|
||||
expect(typeof fakeWindow[url[1]]).toEqual($function);
|
||||
fakeWindow[url[1]]('data');
|
||||
expect(callback).wasCalled();
|
||||
expect(log).toEqual('200:data;');
|
||||
expect(log).toEqual('remove();200:data;');
|
||||
expect(typeof fakeWindow[url[1]]).toEqual('undefined');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue