Recently, ajax technology is widely used in projects, but ajax applications are proneForward and backwardThe button is invalid and does not generate the forward and backward functions. This is a headache. It seriously damages the user's good experience.Location. hashTo solve the problem that the browser's forward and backward buttons become invalid during the Ajax process.
Ybole. hash = {
Url :'',
SetHash: function (){
If (a. join) a = a. join ('/');
$. Browser. msie? $. LocationHash (a): location. hash =;
},
DoHash: function (){
Var h = location. hash. replace ('#', ''). split ('/');
If (Ybole. hash. url. join ()! = H. join ()){
Y. searchKeyword (h [0], h [1], h [2]);
}
}
}
$ (Window). hashchange (function (){
Ybole. hash. doHash ();
});
Here we mainly talk about how to solve the problem of repeated loading that people often encounter before, mainly comparing the hash values before and after, to see if they are equal, and then determining whether ajax is triggered.
Ybole. hash. url = [p. data. search, p. cate, Ybole. page. curpage];
Ybole. hash. setHash (Ybole. hash. url); this is in the ajax callback function. It saves the hash value after ajax to avoid repeated triggering when the hash value changes
A hashchange plug-in of jquery is also used.