![]() |
Ajax stops working after first click - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Ajax stops working after first click (/showthread.php?tid=28370) |
Ajax stops working after first click - El Forum - 03-09-2010 [eluser]bondjp[/eluser] So my problem is that ajax only works when i click "nextweeklink" link for the first time, it updates the table with next week's appointments and then stops working when i try and click again "nextweeklink" but firebug says script was OK. Thanks ResultsView Code: [removed] ajax_nextweek Controller Code: //pagination Ajaxview - ajax_timeslots view (It will replace my calendar appointments) Code: <div id="result_dr"> Ajax stops working after first click - El Forum - 03-09-2010 [eluser]Kamarg[/eluser] If I'm reading this correctly, you're actually replacing your nextweeklink element when you do the .load and fill in a bunch of new html including a new nextweeklink. Since the click event was bound to the now removed link, your new links have no javascript action associated to them. You either need to bind the click event to the new nextweeklink element after the .load or rework it so you don't replace the original. Edit: Just read the livequery plugin description. Seems like it should be taking care of this for you and so you can ignore my post. 2nd Edit: From further in the livequery documentation. Quote:When an element no longer matches a selector the events Live Query bound to it are unbound. The Live Query can be expired which will no longer bind anymore events and unbind all the events it previously bound. It looks like it's saying that if at any time there aren't any nextweeklink items, it will unbind the event completely. So possibly this is still your problem. Ajax stops working after first click - El Forum - 03-09-2010 [eluser]bondjp[/eluser] The links for "nextweek" and "prevweek" are like this: <th class="prev_week" id="prev_week"> <a class="prevWeekLink" id="prevweeklink" rel="nofollow" title="search prev week">Prev. Week</a> </th> <th class="next_week" id="next_week"> <a class="nextWeekLink" id="nextweeklink" rel="nofollow" title="search next week"> </th> Ajax stops working after first click - El Forum - 03-09-2010 [eluser]bondjp[/eluser] [quote author="Kamarg" date="1268175226"]If I'm reading this correctly, you're actually replacing your nextweeklink element when you do the .load and fill in a bunch of new html including a new nextweeklink. Since the click event was bound to the now removed link, your new links have no javascript action associated to them. You either need to bind the click event to the new nextweeklink element after the .load or rework it so you don't replace the original.[/quote] Yes, you're right i replace it with a new one from the ajax_timeslots view. I thought livequery would take care of bind it for me. Can you point me on how can i do it? Thanks Ajax stops working after first click - El Forum - 03-09-2010 [eluser]Kamarg[/eluser] The easiest thing would be to get rid of the livequery. Stick the anonymous function into a non-anonymous function and code an onclick attribute into your nextweeklink element in your view. There's plenty of other ways to do it but that's the simplest that I can think of right now. Ajax stops working after first click - El Forum - 03-09-2010 [eluser]bondjp[/eluser] [quote author="Kamarg" date="1268204068"]The easiest thing would be to get rid of the livequery. Stick the anonymous function into a non-anonymous function and code an onclick attribute into your nextweeklink element in your view. There's plenty of other ways to do it but that's the simplest that I can think of right now.[/quote] Thanks, can you point me to some examples? Sorry but i'm new to jquery. Ajax stops working after first click - El Forum - 03-10-2010 [eluser]Kamarg[/eluser] Remove the $(document).ready() function and replace it with the below code. Code: function bindClick() { Then anywhere you have Code: <a class="nextWeekLink" id="nextweeklink" rel="nofollow" title="search next week">Next Week</a> add Code: onclick="return bindClick();" It's untested but I think it should do the trick. Ajax stops working after first click - El Forum - 03-10-2010 [eluser]bondjp[/eluser] Still no luck ![]() Anymore ideas? Thanks. Ajax stops working after first click - El Forum - 03-10-2010 [eluser]bondjp[/eluser] Just tried to do appendTo instead of ReplaceAll to see if something was called and the first click it shows the correct values but the second just shows a copy of the first click. |