javascript - How can I interrup slow ajax request, running in background -
the situation:
user visit fast loading page, makes ajax async request slow php script, loads, example, 30 seconds
after 3 seconds user clicks link go fast loading page, browser waits 27 seconds finish ajax request slow script, , after starts load next page
how can solve problem? how tell web server interrupt processing request, started defined ajax call?
ps. abort() not solution
pps. code example: page includes filter of shop products, loads longer other page components. after first load filter cached - next times loads fast. when page loads, don't show filter, add js, calls current page again using ajax, adding parameter (show_filter). if page receive parameter - shows filter...
<div id="catalog_filter_container"> <?if($_request['show_filter'] == "y"):?> ... filter code here ... <?endif;?> </div> <?if($_request['show_filter'] != "y"):?> <script type="text/javascript"> $(document).ready(function(){ $.ajax({ url: "<?=$application->getcurpageparam("show_filter=y", array("show_filter")); // cur url adding param show_filter=y ?>" }) .done(function(html) { $("#catalog_filter_container").append($(html).find('#catalog_filter_container')); }); }); </script> <?endif;?>
if understand correctly not neccessary have ajax-call because page reloaded anyway. seems can server-side (with sessions).
something this: (if thing want achieve store value filter when filter not set , display value filter when set)
<?php session_start(); ?> <div id="catalog_filter_container"> <?if($_request['show_filter'] == "y") { $_session['filter_content'] = 'bla bla bla'; } else { echo $_session['filter_content']; } ?> </div>
Comments
Post a Comment