Tuesday, 20 August 2013

Cannot get ajax post to work

Cannot get ajax post to work

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');
}
});
});
});

No comments:

Post a Comment