function do_login()
{
$('.loginsubmit').click(function(e)
{
var datum=$('.loginform').serialize();
$.ajax({
type: "POST",
url: "login",
data: datum,
contentType: "application/json; charset=utf-8",
dataType:"json",
success: function(data)
{
if(data.prop=="false")
{
$('p#login-error-notif').text(data.error);
}
else if(data.prop=="true")
{
$('#logindrp span').text("Welcome "+data.name);
}
}
});
});
} //closing do_login function
This is the function called when user click on the Login the button. The error I see is the Uncaught reference error: 'prop' of null.
The code in the PHP page is
if(isset($_POST['username']))
{
$username=$_POST['username']
...// proceed with checking the username and password
if($check_login)
{
$return=array(prop=>"true", name=>$name, username=>$username);
echo json_encode($return);
}
else
{
$return=array(prop=>"false", error=>"Invalid username/password.");
echo json_encode($return);
}
}
But I observed this part is not being executed. I mean the 'username' is not sent to the page. I checked it with adding the code setcookie("username", $username); inside it. The cookie is never created. What is the problem in my AJAX request?
usernameis not indatum. But what data is? Check with sth like$.each(datum, function(key, value) { alert(key +' => '+ value); });usernameandpassword. Also I passed username and password individually. But no use.data: datumand add php last json echo to question.data?