Created
September 16, 2015 12:28
-
-
Save cdmz/96b2b5f0628624279774 to your computer and use it in GitHub Desktop.
jquery ajax with abort previous xhr
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_ = null ,xhr = null,timeout_seconds = 10*1000 ; | |
| $("body").on('click',function(){ | |
| load_ajax(); | |
| }); | |
| function load_ajax(){ | |
| xhr_ = xhr; | |
| xhr = $.ajax({ | |
| url: 'http://localhost/teste.php', | |
| type: 'GET', | |
| dataType: 'json', | |
| timeout: timeout_seconds, | |
| data: { | |
| dados: 'value1' | |
| }, | |
| beforeSend: function(){ | |
| if( xhr_ != null && typeof xhr_ == 'object' ) { | |
| xhr_.abort(); | |
| } | |
| }, | |
| success: function(response , status, xhr){ | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment