I've implemented the changes you've suggested, but I'm seeing the same
issue (clicks are not being intercepted by JQuery).  :-/  I do
understand what you suggested, but I'm now very confused as to why it
isn't working.

Is there a way to see, at the current time, what links have the click
handler attached correctly?

-Ray

On Dec 12, 2:12 pm, brian <bally.z...@gmail.com> wrote:
> On Fri, Dec 12, 2008 at 2:24 PM, ray <rayjohnterr...@gmail.com> wrote:
>
> > could you show me an example of what you mean here by this, either
> > using the code above or another example?  That sounds like the
> > 'correct' way to do it.
>
> >     [ set the click handler to be a separate function and ensure that
> > any new links also get the click handler attached (in your success
> > block) ]
>
> Something along these lines:
>
> $('.ajax_link').click(my_click);
>
> function my_click()
> {
>         clicked_link_id = $(this).attr("id");
>         $.ajax({
>                 dataType: "text",
>                 type: "POST",
>                 url: "ajax.php",
>                 data: "a=" + clicked_link_id,
>                 success: function (msg, status)
>                 {
>                         $("#maintext").fadeOut("slow", function()
>                         {
>                                 $(this).html(msg)
>                                         .children('.ajax_link')
>                                         .click(my_click).end()
>                                         .fadeIn("slow");
>                         });
>                 },
>                 error: function(XMLHttpRequest, textStatus, errorThrown) {
>                         alert("Error:");
>                 }
>         });
>         return false;
>
> }
>
> The click handler is no longer an anonymous function and so click() is
> given the name only. This will allow you to run click(my_click) on any
> new links added to the page when the successfunction runs.
>
> Though it's not necessary, you could also do the same with the success 
> function:
>
> success: mysuccess,
> ...
>
> function my_success(msg, status)
> {
>         $("#maintext").fadeOut("slow", function()
>                 {
>                         $(this).html(msg)
>                                 .children('.ajax_link')
>                                 .click(my_click).end()
>                                 .fadeIn("slow");
>                 });
>
> }
>
> Note that I've also changed your success function. You don't need
> document.getElementById as you can get at it with jQuery(). Also, I've
> used $(this) in the callback instead of looking for #maintext again.
> And I've chained the functions together. The end() is there so that
> fadeIn() applies to #maintext and not the links.

Reply via email to