I'm working on a login script, and I want to send the input to a PHP script, check it, and then do something if it matches the one I have in the config.php file.
pseudo php code (admin_login.php)
<?php
require("../config.php");
if($_POST['password'] == $password) {
$showLoginPage = true;
}
else {
$showLoginPage = false;
}
?>
jQuery:
$("#admin_login_submit").click(function(event) {
event.preventDefault();
var pass = $("#admin_login_password").val();
$.post("includes/process/admin_login.php",
{ password: pass },
function(data){
$("#show_admin_feedback").html(data);
});
If I could magically create jQuery code, what I want to do would look like this:
$("#admin_login_submit").click(function(event) {
event.preventDefault();
var pass = $("#admin_login_password").val();
$.post("includes/process/admin_login.php",
{ password: pass },
function(data){
$("#show_admin_feedback").html(data);
showLoginPage = $showLoginPage;
});
if(showLoginPage == true) {
$("#main").load("logged_in.php");
}
});
Oh, I have $("#show_admin_feedback").html(data);
being returned because I was returning "Worked" or "Didn't work" when I was testing it. :-p.
------Fixed. Thanks, jitter!
php
<?php
require("../config.php");
if($_POST['password'] == $password) {
header('HTTP/1.1 200 OK');
}
else {
header('HTTP/1.1 404 Not Found');
}
?>
jQuery
$("#admin_login_submit").click(function(event) {
event.preventDefault();
var pass = $("#admin_login_password").val();
$.ajax({
type: "POST",
url: "includes/process/admin_login.php",
data: "password=" + pass,
success: function(){
$("#main").load("logged_in.php"); },
error: function(){
$("#admin_login_show").html("<b>Failed Login</b>"); }
});
});