无法获得Ajax发布信息

I am able to the js file to fire which does do the first alert but i cannot get the 2nd alert to happen, php file is there and working returning 0 but the alert('finished post'); is not coming up. I think its some syntax I am missing.

$(function () {
$("#login_form").submit(function () {
    alert('started js');
    //get the username and password  
    var username = $('#username').val();
    var password = $('#password').val();

    //use ajax to run the check  
    $.post("../php/checklogin.php", { username: username, password: password }, 
        function (result) {
            alert('finished post');
            //if the result is not 1  
            if (result == 0) {
                //Alert username and password are wrong 
                $('#login').html('Credentials wrong');
                alert('got 0');
            }
    });
});

});

Here is the php

session_start();
include 'anonconnect.php';

// username and password sent from form 
$myusername= $_POST['username']; 
$mypassword= $_POST['password']; 

$sql = $dbh->prepare("SELECT * FROM Users WHERE UserLogin= :login");
$sql->execute(array(':login' => $myusername));
$sql = $sql->fetch();

$admin = $sql['admin'];

$password_hash = $sql['UserPass'];
$salt = $sql['salt'];

/*** close the database connection ***/
$dbh = null;

if(crypt($mypassword, $salt) == $password_hash){
    // Register $myusername, $mypassword and redirect to file
    $_SESSION['myusername'] = $myusername;
    $_SESSION['loggedin'];
    $_SESSION['loggedin'] = 1;

    if($admin == 1){
        $_SESSION['admin'] = 1;
    }

    header("location:search.php");
}
else {
    $_SESSION['loggedin'];
    $_SESSION['loggedin'] = 0;
    echo 0;
}
查看全部
weixin_33698823
weixin_33698823
2013/08/21 03:29
  • php
  • ajax
  • javascript
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信

4个回复