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

Function jsonpReq

test/angular/1.6/angular.js:13036–13071  ·  view source on GitHub ↗
(url, callbackPath, done)

Source from the content-addressed store, hash-verified

13034 };
13035
13036 function jsonpReq(url, callbackPath, done) {
13037 url = url.replace('JSON_CALLBACK', callbackPath);
13038 // we can't use jQuery/jqLite here because jQuery does crazy stuff with script elements, e.g.:
13039 // - fetches local scripts via XHR and evals them
13040 // - adds and immediately removes script elements from the document
13041 var script = rawDocument.createElement('script'), callback = null;
13042 script.type = 'text/javascript';
13043 script.src = url;
13044 script.async = true;
13045
13046 callback = function(event) {
13047 script.removeEventListener('load', callback);
13048 script.removeEventListener('error', callback);
13049 rawDocument.body.removeChild(script);
13050 script = null;
13051 var status = -1;
13052 var text = 'unknown';
13053
13054 if (event) {
13055 if (event.type === 'load' && !callbacks.wasCalled(callbackPath)) {
13056 event = { type: 'error' };
13057 }
13058 text = event.type;
13059 status = event.type === 'error' ? 404 : 200;
13060 }
13061
13062 if (done) {
13063 done(status, text);
13064 }
13065 };
13066
13067 script.addEventListener('load', callback);
13068 script.addEventListener('error', callback);
13069 rawDocument.body.appendChild(script);
13070 return callback;
13071 }
13072}
13073
13074var $interpolateMinErr = angular.$interpolateMinErr = minErr('$interpolate');

Callers 1

createHttpBackendFunction · 0.70

Calls 1

doneFunction · 0.70

Tested by

no test coverage detected