Ok alexandre... you got it! ;-)

yes, the markup for the login div is loaded on page load while the
logout button markup is loaded later via ajah trough sign_in.php.
In fact the server send this command:
$("#welcome_div").html("<b>Welcome</b> <i>$_user</i>!!! <br/> <a
href='#' id='log_out_link'> Log out </a>");
and then Javascript evals it.

As you told me this issue is quite usual and in fact I had though
about that... but now I tell you why I still did that mistake.

Anyway, the problem is solved... the livequery plugin is amazing!
Thanks Alexandre.
This is just a "pour parle"... maybe in order to clarify an
issue... ;-)

Well, in the website on which I'm working when you click on the "Sign
Up" link the server sends the form and all the javascript functions I
need to make it works:
$("#sign_up_div").load("server_scripts/
sign_up_div.php").css({visibility: "visible"});
so, now the DOM has been modified but anyway it still works and I
though because of the fact that I loaded also the javascript functions
together with the new markup...

In the mistake of the "Log Out" link I though to do the same... via
ajax (instead than with a load function) I changed the content of a
div with html markup language and I loaded the javascript functions
evaluating them...
Here the js code is:
$(document).ready(function(){
        $("#log_out_link").click(function(){
                alert("Log out in progress...");
                $.post("server_scripts/log_out.php",
                        function(response){
                                alert("log out succesfully done...");
                                eval(response);
                        }
                );
        });
});
                $("#welcome_div").html("<b>Welcome</b> <i>$_user</i>!!! <br/> <a
href='#' id='log_out_link'> Log out </a>");

The two way of proceeding seem similar to me...

Anyone can find out what's the difference?!?

If you think I'm a bit confused 'cause I don't see the real
difference... yes, I'm a bit confused!!! hehe...



By the way guys, thank you very much at all for the great support!!!

Cheers



On Apr 26, 10:06 pm, "Alexandre Plennevaux" <[EMAIL PROTECTED]>
wrote:
> ok ^AndreA^, i think  i got it.
>
> I think the markup for the login div is loaded on page load, while the
> logout button markup is fetched via your ajax call to "sign_in.php", right?
>
> In such case the issue you are facing is normal, and quite usual: the event
> binding is set on page load. Since your logout link markup does not exist
> yet, the event is not binded, whereas your div markup is available on
> document ready, so its event does work.
>
> the best solution is to use the livequery plugin, which allows to bind
> events even to markup that is not available at the document.ready time.
>
> Its a really useful plugin , since you do your application using ajax, i can
> only strongly recommend you to use it.
>
> after you will have added the link to the plugin in your page header you can
> simply use it like this:
>
> instead of:
>
> $('#log_out_link').bind('click',function(){])
>
> you go:
>
> $('#log_out_link').livequery('click',function(){])
>
> hope this helps,
>
> alexandre

Reply via email to