JavaScript:Asynchronous download js,when the download fails, how to call the error function
<p>A common asynchronous download js function as follows.</p>

<p>But when the download fails, how to call the error function.</p>

<p>This function will be: function loadScript(url, callback, errcb).</p>

<pre><code>function loadScript(url, callback){ 
    var script = document.createElement("script") 
    script.type = "text/javascript"; 
    if (script.readyState){ //IE 
        script.onreadystatechange = function(){ 
            if (script.readyState == "loaded" || script.readyState == "complete"){ 
                script.onreadystatechange = null; 
                callback(); 
            } 
         }; 
    } else { //Others: Firefox, Safari, Chrome, and Opera 
        script.onload = function(){ 
            callback(); 
        }; 
    } 
    script.src = url; 
    document.body.appendChild(script); 
} 
</code></pre>
