Reputation: 373
i have working on ajax search functionality but facing one issue.let me quick explain sample code below.
function search_content(sh_val,sh_act)
{
....some search code.....
window.location.hash = sh_val+'@'+sh_act;
}
I have use following function for restore the search when clicked on browser back or forward button.
$(window).bind( 'hashchange', function(e) {
var pagee=location.hash.slice(1)
if (pagee!="")
{
search_content(pagee,'catsh');
}
return false;
});
but i am facing issue when i am search ajax search function is called twice. $(window).bind( 'hashchange') is also called when i am searching.is there any way to call the above function only for browser back and forward button or any other solution ?
how can i resolve this issue?
I would appreciate anykind of help..
Upvotes: 1
Views: 408
Reputation: 6131
try .on()
instead of bind and look for manual triggers. Also a stop propagation maybe?
Why applying on window instead of document?
You can also add a debugger command :
$(window).on( 'hashchange', function(e) {
debugger;
e.stopPropagation();
[...]
});
Upvotes: 1