I have been having a really hard time getting ajax working with PHP for a web application. I want to use jQuery's ajax() method to asynchronously login a user when he enters correct information into a login form.
The biggest thing I don't realize is HOW the freak does jQuery decipher the difference between a "success" script and an "error" script. It seems that pretty much anything I put into my PHP page, the success
callback always gets called and error
never does. Am I doing something wrong?
data: "username=" + $("#username").val() + "&password=" + $("#password").val() + "&public_computer=" + $("#public_computer").val(),
alert("successful" + msg);
alert("unsuccessful" + msg);
This is my very basic 'login.php' page. Despite the exit
and the syntax error, the success() jQuery callback is always called
THIS IS A SYNTAX ERROR
$_SESSION['authenticated']['status'] = true;
$_SESSION['authenticated']['user_id'] = 1;
When I click the "login" button of the login form, it says: successful<br />
<b>Parse error</b>: syntax error, unexpected T_STRING in <b>C:\xampp\htdocs\senior_project\ajax\login.php</b> on line <b>8</b><br />
Furthermore, even when I remove the syntax error and the code to kill the script, the SESSION variables that I try to set don't seem to be set for the rest of the application. I need these SESSION variables to be set to keep the user logged in. EDIT: NEVERMIND about this part. I figured out it's because I forgot session_start(). DUH!
Help GREATLY appreciated. I've been stuck on this for way too long and it is frustrating.