CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2007
    Posts
    18

    Ajaxifying Login

    Hello,

    I want to ajaxify my Login page written in jsp. I already wrote the "verify_login" function which return a boolean value: either true or false.

    Now the point is that I dunno how to retrieve this boolean value into my ajax script. I know nothing about Ajax, I just saw this code and im trying to do the same: http://woork.blogspot.com/2007/10/lo...x-and-php.html

    In the following code, the result of the login page is a value of 0 if the login fails, or the function returns the username in the other case. In my case, I wanna test: if (response == false) ... how can I do it ? it's not working

    Code:
    function loginReply() {
    if(http.readyState == 4){
    var response = http.responseText;
    if(response == 0){
    // if login fails
    document.getElementById('login_response').innerHTML = 'Login failed! Verify user and password';
    // else if login is ok show a message: "Welcome + the user name".
    } else {
    document.getElementById('login_response').innerHTML = 'Welcome'+response;
    }
    }

    Thank U in advance

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Ajaxifying Login

    Quote Originally Posted by tima
    In my case, I wanna test: if (response == false) ... how can I do it ?
    You already stated that it returns a 0 if the login fails, or the username if it passes. In this case, you will never receive a false. So why are you trying to check for it?

    Are you refering to whether or not the AJAX request itself fails?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jan 2007
    Posts
    18

    Re: Ajaxifying Login

    still it's not working. My jsp function returns either the username or nothing.

    var response = http.responseTEXt does not return anything!! i dont get this. I tried the alert(response), the alert is empty!

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Ajaxifying Login

    Quote Originally Posted by tima
    var response = http.responseTEXt does not return anything!!
    You should have been more clear and stated that in the first place.

    You also have not posted enough relevant code. Where is your initialization of the HTTP request? May I suggest using my AJAX object?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jan 2007
    Posts
    18

    Re: Ajaxifying Login

    what do u mean by:

    function getUpdate(txt){
    document.getElementById('getReturn').innerHTML = 'GET=' + txt;
    }
    function postUpdate(txt){
    document.getElementById('postReturn').innerHTML = 'POST=' + txt;
    }

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: Ajaxifying Login

    Below is the AJAX object. The code above are examples of how to reference the object properly. Put the object itself in a .js file and link to it within the <head> tag. Then to call it, you would want something similar to the following.

    Code:
    function postUpdate(txt){
      //txt would be the returned text
      if(response == 0){
        document.getElementById('login_response').innerHTML = 'Login failed! Verify user and password';
      }
      else{
        document.getElementById('login_response').innerHTML = 'Welcome' + response;
      }
    }
    
    AJAX.post('login.php', 'user=' + user + '&pass=' + pass, postUpdate);
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured