使用jQuery防止过时的Ajax数据
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用jQuery防止过时的Ajax数据相关的知识,希望对你有一定的参考价值。
When running live filters on large, long scripts you can get old, stale results replacing your new, fresh ones. After all, a search for everything containing 'S" in a large database of city names can take a lot longer than "Seattle", so your script gets the results for "Seattle", displays then, then it gets the results for "S" and displays them, replacing the "Seattle" search you really wanted.This script aborts the previous call before making the new one, effectively preventing that from happening. There are 2 caveats though.
1. The server may continue to process the request (depending on setup).
2. The error console logs it as an error, but not a fatal one and no alerts are thrown so the normal end user wont notice.
I have some more information available at the URL.
function ajax_get(){ if(getting!=''){getting.abort();} $('#loading_animation').fadeIn(); filter = $.get('/path/to/ajax.file', function(data) { $('#loading_animation').fadeOut(); }); }
以上是关于使用jQuery防止过时的Ajax数据的主要内容,如果未能解决你的问题,请参考以下文章
在服务器端分页上防止来自 jquery 数据表的多个 ajax 调用