Hi,
I have a function that does the following:
- binds all images on the page to a click handler.
- when clicked, unbinds then makes a ajax request
- binds the link again.
Theoretically this should work correct? (sorry don't have the code with me)
Hi,
I have a function that does the following:
Theoretically this should work correct? (sorry don't have the code with me)
Could you provide more information? Why do you unbind the event handlers? Is this just to prevent one from clicking again and getting a second ajax call, while the first is still running? If so, I would do it differently: Bind the handler to the images and leave them binded. If someone clicks an image, your handler gets called. The handler then starts an ajax request and sets a flag (e.g. loading = true). If the images are clicked again, the function ignores that as long as loading is true. If the request is done, you reset your loading-flag to false.
This technique is often used and should be faster then walking over the DOM, find the elements bind event handlers and so on. As a side effect, you now have a loading flag that could be used to display a throbber while loading.