简体   繁体   中英

Prevent mouse releases from happening twice

I am using JQuery. I would like to send some JSON to the server when the user releases the mouse. Currently, the JSON is getting sent twice. How can I prevent it from happening?

Without seeing your code, it's a little challenging to understand the intent; but: you probably either are looking to do a debounce/throttle—if it's the case that a user is performing multiple clicks, and you want to ensure that a double-click would only send once within a certain timeframe—or if you really only want it to submit once and then never again, you could create a fire-once closure.

Functions that do everything you need are available in the popular underscore.js and lodash libraries. For example, in underscore:

Depending on what you're looking for, one of these functions will likely do it. The source for underscore.js is also very readable, so you can dig in and see how they're accomplishing this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM