Posted By

johnloy on 10/05/09


Tagged

ajax javascript textmate


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

inkdeep


import function to synchronously load external javascript files


 / Published in: Other
 

  1. function import(url)
  2. {
  3. var req = new XMLHttpRequest();
  4. var isSuccessful = function() {
  5. try {
  6. return ( req.status >= 200 && req.status < 300 ) || req.status == 304 || navigator.userAgent.indexOf("Safari") >= 0 && typeof req.status == "undefined";
  7. } catch(e){}
  8. return false;
  9. }
  10. req.open('GET', url, true);
  11. req.onreadystatechange=function() {
  12. if ( req.readyState == 4) {
  13. if(isSuccessful()) {
  14. eval.call( window, req.responseText );
  15. }
  16. }
  17. }
  18. req.send();
  19. };

Report this snippet  

You need to login to post a comment.