I ask for advice on jQuery

    Good day to all!
    I learn jQuery and write ajax authorization for my site. jQuery is a great framework. I do not understand javascript and it is unlikely that I could write ajax authorization on it. Thanks to jQuery for such a wonderful miracle!
    Below I have given the authorization code. In general, everything works correctly, but after the user has logged in, then by clicking on the "Exit" link the loginout event does not occur, and if you reload the page, it will work. The same thing after the user logs out - without reloading the page, he will no longer be able to log in. Maybe someone will tell you how to solve the problem?

    I will also be grateful for the comments and comments on the code.

    1. $(document).ready(function(){
    2. //ajax login
    3.   $("#loginform").bind("submit",function() {
    4.     var qString = $('#loginform').formSerialize();
    5.     $.getJSON('login.html', qString, function(json){
    6.       if(json.result == 1){
    7.         $('#login').html('');
    8.         $('#login').append('' + json.login + ' Выход');  
    9.         $("#logout").bind("click",function() {
    10.           $('#login').load("logout.html");;
    11.           return false;
    12.         });
    13.       } else {
    14.         $('#msg').html('');
    15.         $('#msg').append('Неверно введён логин или пароль');
    16.       }
    17.     });
    18.     return false;
    19.   });
    20. //end ajax login
    21. //ajax logout
    22.   $("#logout").bind("click",function() {
    23.     $('#login').load("logout.html");
    24.     return false;
    25.   });
    26. //end ajax logout
    27. });
    28. //end document.ready
    * This source code was highlighted with Source Code Highlighter.


    Also popular now: