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

Function jsonpReq

test/angular/1.2/angular.js:8698–8744  ·  view source on GitHub ↗
(url, callbackId, done)

Source from the content-addressed store, hash-verified

8696 };
8697
8698 function jsonpReq(url, callbackId, done) {
8699 // we can't use jQuery/jqLite here because jQuery does crazy shit with script elements, e.g.:
8700 // - fetches local scripts via XHR and evals them
8701 // - adds and immediately removes script elements from the document
8702 var script = rawDocument.createElement('script'), callback = null;
8703 script.type = "text/javascript";
8704 script.src = url;
8705 script.async = true;
8706
8707 callback = function(event) {
8708 removeEventListenerFn(script, "load", callback);
8709 removeEventListenerFn(script, "error", callback);
8710 rawDocument.body.removeChild(script);
8711 script = null;
8712 var status = -1;
8713 var text = "unknown";
8714
8715 if (event) {
8716 if (event.type === "load" && !callbacks[callbackId].called) {
8717 event = { type: "error" };
8718 }
8719 text = event.type;
8720 status = event.type === "error" ? 404 : 200;
8721 }
8722
8723 if (done) {
8724 done(status, text);
8725 }
8726 };
8727
8728 addEventListenerFn(script, "load", callback);
8729 addEventListenerFn(script, "error", callback);
8730
8731 if (msie <= 8) {
8732 script.onreadystatechange = function() {
8733 if (isString(script.readyState) && /loaded|complete/.test(script.readyState)) {
8734 script.onreadystatechange = null;
8735 callback({
8736 type: 'load'
8737 });
8738 }
8739 };
8740 }
8741
8742 rawDocument.body.appendChild(script);
8743 return callback;
8744 }
8745}
8746
8747var $interpolateMinErr = minErr('$interpolate');

Callers 1

createHttpBackendFunction · 0.70

Calls 5

doneFunction · 0.70
isStringFunction · 0.70
callbackFunction · 0.70
removeEventListenerFnFunction · 0.50
addEventListenerFnFunction · 0.50

Tested by

no test coverage detected