这是我需要多个请求并仅处理最后一个请求时使用的模式:
var fooXHR, fooCounter=0;$(...).bind( 'someEvent', function(){ // Do the Right Thing to indicate that we don't care about the request anymore if (fooXHR) fooXHR.abort(); var token = ++fooCounter; fooXHR = $.get( ..., function(data){ // Even aborted XHR may cause the callback to be invoked if (token != fooCounter) return; // At this point we know that we're using the data from the latest request });});
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)