Как-то так, например:
function js_include(src, onload, onerror) {
var js = document.createElement('script');
js.onload = onload;
js.onerror = onerror;
js.setAttribute('type', 'text/javascript');
js.setAttribute('src', src);
js.setAttribute('defer', 'defer');
document.getElementsByTagName('HEAD')[0].appendChild(js);
}
js_include('http://code.jquery.com/jquery-1.7.1.js', function(){
alert('load: http://code.jquery.com/jquery-1.7.1.js');
}, function(){
alert('error: http://code.jquery.com/jquery-1.7.1.js');
});
js_include('http://code.jquery.com/jquery-1.7.1.js.error', function(){
alert('load: http://code.jquery.com/jquery-1.7.1.js.error');
}, function(){
alert('error: http://code.jquery.com/jquery-1.7.1.js.error');
});