Bug about multiple requests caused by repeated addition of hash in jquery hashMap
Jquery hashMap is a plug-in that monitors changes in the hash of the browser, and processes more hash changes accordingly. I read the source code loaded by the event to understand the cause. I stepped on some pitfalls between them and wrote them down. I hope they can help people who will use them later. The main principle is to listen to the hashchange event of the browser and then distribute the event. This plug-in was recently used in the project by Using ajax to process the event, our project uses jqeury's ajax update to asynchronously load the page and append the page to the corresponding region, at first, I thought that the js of the page was repeatedly loaded when ajaxUpdate loaded the page, causing two events to trigger on my page, therefore, when performing the next operation on the page, you will find that all the methods correspond to a dom layer. If the form is submitted, it will be submitted multiple times at the same time. In this case, the data returned by the backend is also abnormal. When the hash parameter is added to hashchange, the original code is as follows:
$..= (options) { = ; = .; (Object...(options) === ) { (== ) { .= Array(); (= options.- ; >= ; --) { ..(options[]); ..(, [options[]]); } } { (= options.- ; >= ; --) { = ; () { ([].== options[].) { .(+options[].); = ; } } (!){ ..(options[]); ..(, [options[]]); } } } ; } (){ (== ){ .= Array(); ..(); } ..(, ) };};$..= (options) { = ; = .; (Object...(options) === ) { (= options.- ; >= ; --) { ..(, [options[]]); } } ; } ..(, );};
It turns out that when he adds the hash parameter again, it does not sort the weight. Therefore, many hash parameters are added, which will trigger an event multiple times.
$..= (options) { = ; = .; (Object...(options) === ) { (== ) { .= Array(); (= options.- ; >= ; --) { ..(options[]); ..(, [options[]]); } } { (= options.- ; >= ; --) { = ; () { ([].== options[].) { .(+options[].); = ; } } (!){ ..(options[]); ..(, [options[]]); } } } ; } (){ (== ){ .= Array(); ..(); } ..(, ) };};$..= (options) { = ; = .; (Object...(options) === ) { (== ) { .= Array(); (= options.- ; >= ; --) { ..(options[]); ..(, [options[]]); } } { (= options.- ; >= ; --) { = ; () { ([].== options[].) { .(+options[].); = ; } } (!){ ..(options[]); ..(, [options[]]); } } } ; } (){ (== ){ .= Array(); ..(); } ..(, ) };};