Created
November 25, 2015 20:50
-
-
Save jalex19100/9ae1365cba42d8c42cd9 to your computer and use it in GitHub Desktop.
Grab only the most recently requested ajax call to avoid the response getting overwritten by older calls
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 handleSuccess = (function () { | |
var latestRequestTimestamp = 0; | |
return function handleSuccess(timestamp, data) { | |
if (timestamp < latestRequestTimestamp) { return; } | |
latestRequestTimestamp = timestamp; | |
/ stuff | |
}; | |
}); | |
$.ajaxSetup({contentType: "application/json"}); | |
$.getJSON(url, params) | |
.done(function (data) { | |
handleSuccess(requestTimestamp, data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment