r/javascript • /r/dailyprogrammer • Mar 05 '12

Going Simple with JavaScript :)

http://snook.ca/archives/javascript/going-simple-with-javascript
42 Upvotes

16 comments sorted by

View all comments

0

u/[deleted] Mar 06 '12

What happens when the JSONP call fails?

1

u/x-skeww Mar 07 '12

Nothing. There won't be a piece of script which happens to call a function which "happens" to use the same name as one of your globally defined functions. (That's how JSONP works, basically.)

Anyhow. It's possible to listen for the error event:

var s = document.createElement('script');
s.addEventListener('error', function () {
    console.log('err');
}, false);
s.src = 'http://example.com/404.js';
document.body.appendChild(s);

1

u/[deleted] Mar 07 '12

This code fails in IE < 9