ajax - slowness when using hashchange event -
i have website uses ajax paging, page scheme works according hashchange event, whenever want move page, phone call function alter hash page number, when hash changed hashchange event fired , phone call function page info . however, works except 1 thing, if alter page more 3-4 times page not respond , crash, check network tap in inspect element in google chrome , see when alter page number of ajax requests doubled , transferred info doubled, cause memory leak. eventually, i've tried paging thing without hashchange see if problem solved, , worked charm. can please till me ? in advance
hashchange event
$(window).bind('hashchange', function () { search(0); });
changehash function
function changehash(p) { window.location.hash = p; }
page button
$('#pages').append("<button type='button' class='btn btn-default"+active+"' onclick=\"changehash(" + + ")\">" + + "</button>");
the code you've given doesn't show it, what's happening after each xhr re-running bind call.
hence, double, triple, quadruple binding event unintentionally - exactly network log shows: haschange running 2,3,4,5 ... times until browser crashes.
to avoid this, create sure
$(window).bind('hashchange', function () { search(0); });
is run once.
ajax paging hashchange
No comments:
Post a Comment