mlhaufe

Binary XHR

May 2nd, 2011
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function loadBinary(url){
  2.     var xhr = (typeof ActiveXObject == "function") ?
  3.         new ActiveXObject("Msxml2.XmlHttp.6.0") :
  4.         new XMLHttpRequest();
  5.  
  6.     xhr.open("GET",url,false);
  7.  
  8.     if(typeof typeof xhr.overrideMimeType == "function")
  9.         xhr.overrideMimeType("text/plain; charset=x-user-defined");
  10.    
  11.     xhr.send(null);
  12.    
  13.     if(xhr.status != 200) return "";
  14.    
  15.     return (typeof xhr.responseBinary == "function") ?
  16.         xhr.responseBinary :
  17.         xhr.responseText;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment