mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-14 08:53:21 +08:00
refactor($browser.xhr): use $browser.addJs for JSONP
There is no reason why we shouldn't reuse $browser.addJs for JSONP requests.
This commit is contained in:
@@ -89,14 +89,12 @@ function Browser(window, document, body, XHR, $log) {
|
||||
outstandingRequestCount ++;
|
||||
if (lowercase(method) == 'json') {
|
||||
var callbackId = ("angular_" + Math.random() + '_' + (idCounter++)).replace(/\d\./, '');
|
||||
var script = jqLite(rawDocument.createElement('script'))
|
||||
.attr({type: 'text/javascript', src: url.replace('JSON_CALLBACK', callbackId)});
|
||||
var script = self.addJs(url.replace('JSON_CALLBACK', callbackId));
|
||||
window[callbackId] = function(data){
|
||||
delete window[callbackId];
|
||||
script.remove();
|
||||
body[0].removeChild(script)
|
||||
completeOutstandingRequest(callback, 200, data);
|
||||
};
|
||||
body.append(script);
|
||||
} else {
|
||||
var xhr = new XHR();
|
||||
xhr.open(method, url, true);
|
||||
|
||||
Reference in New Issue
Block a user