Experiencing jquery in rails through .js.erb templates; but completely puzzled by a simple problem : for some reason, when a certain controller's action is called, it is recalled like two or three times. and on top of that, the number of recalls to the same action increase as the page is used. so i quickly end up with long loops over the same action... there's a real logic in this bug, but still, can get hat it is and how to solve it. ay experiences with tose kind of problems ?
A:
Try unbind(ing) the event before attaching it. that helps with my stuff from time to time.
If you are using the live keyword then stop using it. if you are not, then try using it. i know that sounds like rubbish advice but i have done these steps in the past to fix issues exactly like you describe.
also, if on your success of the jquery call, ensure you are not rebinding events on a set of objects defined by a class. that will also add events to controls.
griegs
2009-11-03 21:02:39
i don't know this "the live keyword"...but yeah, there's a problem when i bind stuff on a set of object on success, the problem disappear when i remove those.the real problem is that i don't really need to "re"bind onsuccess with the stuff i'm currently working on, but sometimes and randomly the objects gets unbinded…
Ben None
2009-11-04 15:15:34
Right I'm with you. If I have this right then you are trying to bind an event such as click to a control (after) you come back from a jQuery postback right? And you may or may not be creating controls to bind events to. The keyword I think you want is "live". Basically it will bind events to all objects that you specify and all objects to create subsequently without you needing to bind yourself and hence create duplicate events on the existing controls.
griegs
2009-11-04 20:46:29
Check out http://docs.jquery.com/Events/live for an explanation of the "live" keyword.
griegs
2009-11-04 20:47:01
Thx griegs for those explanations ! It sounds like it'll fix this problem, or at least 'll give a check. I'll try and let you know soon.
Ben None
2009-11-05 11:45:50
sorry to be late, but yeah, works now smoothly. big thx !!!!!
Ben None
2009-11-17 16:02:35