Bug about multiple requests caused by repeated addition of hash in jquery hashMap

Source: Internet
Author: User

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();            ..();        }        ..(, )    };};

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.