I don't know what I do wrong..
I have 2 files: login.php index.php
<script type="text/javascript">
$(document).ready(function(){
$('#btnLogin').bind('click', loginToWebsite);
});
function loginToWebsite(){
$.ajax({
url: "login.php",
type: "POST",
data: "username=" + $("#username").val()+"&password=" + $("#password").val(),
datatype:"json",
success: function(status)
{
if(status.success == false)
{
$("#loginform").effect("shake", {times:2}, 100);
$("#login_message")
.attr('class', 'ui-state-error')
.html('<strong>ERROR</strong>: Your details were incorrect.<br />');
}
else {
$("#login_message")
.attr('class', 'ui-state-highlight')
.html('<strong>PERFECT</strong>: You may proceed. Good times.<br />');
}
}
});
}
</script>
login.php gile looks this way:
<?php
if (isset($_POST['username'])&& isset($_POST['password']))
{
if (login ($_POST['username'], $_POST['password'])){
$data = array("success" => true);
echo json_encode($data);
}
else {
$data = array("success" => false);
echo json_encode($data);
}
}?>
But i get undefined back from login.php (via json)
If I try to alert(status.success) it prints undefined
And I can see i the header that the username and password are getting send to the login.php page.
The PHP function login() is implemented elsewhere (and returns true or false)