Last active
          August 29, 2015 14:16 
        
      - 
      
- 
        Save aindong/37d9f7537546ca7bb654 to your computer and use it in GitHub Desktop. 
    Recursive ajax request (polling)
  
        
  
    
      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 checkForNewReading = function () { | |
| $.ajax({ | |
| url: location.href + '/request', | |
| type: 'GEt', | |
| dataType: 'json', | |
| success: function(data) { | |
| if (data) { | |
| // DO SOMETHING | |
| } | |
| checkForNewReading(); | |
| }, | |
| error: function(xhr, ajaxOptions, thrownError) { | |
| console.log(thrownError); | |
| } | |
| }); | |
| }; | |
| checkForNewReading(); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment