title: dynamically creating script: readyState never "complete"
body: <p>I'm trying to do something AFTER a script is completely loaded. (IE8)</p>
  
  <p>Script I use for testing: <a href="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" rel="noreferrer">http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js</a><br>
  and the invalid one: <a href="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.minaaaaaaaa.js" rel="noreferrer">http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.minaaaaaaaa.js</a></p>
  
  <p>The code...
  </p>
  
  <pre><code>var script = create the element and append to head...
  
  // this works fine with FF/Chrome/...
  script.onload = function() {alert('script loading complete');}
  script.onerror = function() {alert('error loading script');}
  
  // and for IE
  script.onreadystatechange = function() {
      // this will alert 1.loading 2.loaded
      alert(this.readyState);
  
      // this never works
      if(this.readyState == 'complete') {alert('script loading complete');}
  
      // this works with either a valid or INVALID url
      else if(this.readyState == 'loaded') {alert('script loaded');}
  };
  </code></pre>
  
  <p>In my case, the "complete" never shows, the "loaded" shows even if a url is invalid. So there's no way to tell if a script is CORRECTLY loaded UNDER IE.  </p>
  
  <p>Am I doing something wrong? How come I never get the complete state?</p>
  
  <h1>UPDATE</h1>
  
  <p>OK, I just read some articles and it seems that readystate is not a reliable way to detect script loading.  </p>
  
  <p>So is there another way to do so? without jQuery, but pure Javascript.</p>