开发者

People who double click everything on web pages... jQuery double click problemo

I have a link on a web page opens up a modal dialog. The first time the link is clicked initialization code executes. Subsequent clicks do not need to do any processing. The problem here is when people double click the link the initializing code runs twice -even thou开发者_如何转开发gh I am setting a flag immediately to say that I am initialized, and if flagged don't run the init function. What should I do?

  • I could unbind the click function on this link when clicked, but then I need to bind the function again when the dialog closes.
  • I could bind to the dblclick event and return false?
  • I could save the 'lastclicked' time on the element, and then check if say 2 seconds has past before letting the event fire?


I use Ben Nadel's jQuery ajax wrapper. Every time you create an ajax request, you can optionally give it a name. The ajax wrapper tracks all named requests and drops any duplicates if it's still waiting on a response from a previous request with the same name.

By putting all your ajax calls through this "pipeline", you have great centralized control over handling every call.


I made a plugin to extend the jquery ajax method and add a singleton flag, with an extra blocking flag to tell ajax to ignore all subsequent calls using this url (or key).

You call ajax normally with extra {singleton:true, blocking:true} options

When you call the same ajax twice the second call does not fire if the first call is still processing. V handy so far:

http://github.com/dougle/jQuery-Ajax-Singleton

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜