Created
          January 9, 2012 15:19 
        
      - 
      
 - 
        
Save sindresorhus/1583375 to your computer and use it in GitHub Desktop.  
    Simple XMLHttpRequest wrapper
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var xhr = function() { | |
| var xhr = new XMLHttpRequest(); | |
| return function( method, url, callback ) { | |
| xhr.onreadystatechange = function() { | |
| if ( xhr.readyState === 4 ) { | |
| callback( xhr.responseText ); | |
| } | |
| }; | |
| xhr.open( method, url ); | |
| xhr.send(); | |
| }; | |
| }(); | |
| /* | |
| xhr('get', 'http://google.com', function(data) { | |
| console.log(data); | |
| }); | |
| */ | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
nice
but as far as I can see there may be problems with setRequestHeader (single XMLHttpRequest object but need to set different headers for different calls)