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;
}
}
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.
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.
Bookmarks