MCPcopy
hub / github.com/angular-ui/ui-router / jsonpReq

Function jsonpReq

test/angular/1.7/angular.js:13607–13642  ·  view source on GitHub ↗
(url, callbackPath, done)

Source from the content-addressed store, hash-verified

13605 };
13606
13607 function jsonpReq(url, callbackPath, done) {
13608 url = url.replace('JSON_CALLBACK', callbackPath);
13609 // we can't use jQuery/jqLite here because jQuery does crazy stuff with script elements, e.g.:
13610 // - fetches local scripts via XHR and evals them
13611 // - adds and immediately removes script elements from the document
13612 var script = rawDocument.createElement('script'), callback = null;
13613 script.type = 'text/javascript';
13614 script.src = url;
13615 script.async = true;
13616
13617 callback = function(event) {
13618 script.removeEventListener('load', callback);
13619 script.removeEventListener('error', callback);
13620 rawDocument.body.removeChild(script);
13621 script = null;
13622 var status = -1;
13623 var text = 'unknown';
13624
13625 if (event) {
13626 if (event.type === 'load' && !callbacks.wasCalled(callbackPath)) {
13627 event = { type: 'error' };
13628 }
13629 text = event.type;
13630 status = event.type === 'error' ? 404 : 200;
13631 }
13632
13633 if (done) {
13634 done(status, text);
13635 }
13636 };
13637
13638 script.addEventListener('load', callback);
13639 script.addEventListener('error', callback);
13640 rawDocument.body.appendChild(script);
13641 return callback;
13642 }
13643}
13644
13645var $interpolateMinErr = angular.$interpolateMinErr = minErr('$interpolate');

Callers 1

createHttpBackendFunction · 0.70

Calls 1

doneFunction · 0.70

Tested by

no test coverage detected