/ Published in: jQuery
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.
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function ajax_get(){ if(getting!=''){getting.abort();} $('#loading_animation').fadeIn(); filter = $.get('/path/to/ajax.file', function(data) { $('#ajax_container').html(data); $('#loading_animation').fadeOut(); }); }
URL: http://fatfolderdesign.com/181/code/prevent-stale-ajax-data-in-jquery