javascript - ajax search function called twice using $(window).bind( 'hashchange', function(e) -
i'm working on ajax search.ajax function called on onblur event.below sample code.
function search_ajax(sh_val,sh_act) { ....some search code..... window.location.hash = sh_val+'@'+sh_act; }
i have made 1 other function restore serch using hash value url when click on browser or forward button.this work , forward button.
$(window).bind( 'hashchange', function(e) { var page=location.hash.slice(1) if (page!="" && page!="p") { search_ajax(page,'catsh'); } return false; });
but facing issue when search ajax search function called twice. $(window).bind( 'hashchange') called when searching.is there way call above function browser , forward button or other solution ?
how can resolve issue?
i appreciate anykind of help..
maybe don't understand well, why did bind hashchange function window??? doesn't make sence. have similar searching function in own apps. not complicated. search function (lets say) same yours:
function search_ajax(sh_val,sh_act) { ....some search code..... window.location.hash = sh_val+'@'+sh_act; }
the 1 performed once per page load:
(function() { var page=location.hash.slice(1) if (page!="" && page!="p") { search_ajax(page,'catsh'); } return false; })();
so, if click search button, search function called. hash changed. 1 step browser history added.
then search, step in history added.
then button. page loaded again, annonymous function performed. hash detected, search performed. , hash changed, becouse hash same before, link same, no duplicite step added history.
Comments
Post a Comment