Skip to content

Instantly share code, notes, and snippets.

@jalex19100
Created November 25, 2015 20:50
Show Gist options
  • Save jalex19100/9ae1365cba42d8c42cd9 to your computer and use it in GitHub Desktop.
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
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