diff options
| author | Misko Hevery | 2011-03-10 14:46:07 -0800 |
|---|---|---|
| committer | Misko Hevery | 2011-03-11 14:16:53 -0800 |
| commit | 0084cb5ca4bc9acda54d304147b0b0fe8e1980f3 (patch) | |
| tree | c64e5aebff8907ebb6af306aa5d9d0fa1062adea | |
| parent | c578f8c3ed0ca23b03ccde146cb13cfaf24f17cd (diff) | |
| download | angular.js-0084cb5ca4bc9acda54d304147b0b0fe8e1980f3.tar.bz2 | |
Remove the script tag after successful JSONP request
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | src/Browser.js | 9 | ||||
| -rw-r--r-- | test/BrowserSpecs.js | 8 |
3 files changed, 11 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e6b2c43..223aac97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/Browser.js b/src/Browser.js index abafb2a5..e51df16c 100644 --- a/src/Browser.js +++ b/src/Browser.js @@ -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); diff --git a/test/BrowserSpecs.js b/test/BrowserSpecs.js index 6951783b..3b5a9ba0 100644 --- a/test/BrowserSpecs.js +++ b/test/BrowserSpecs.js @@ -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'); }); }); |
