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?
It worked well after resolving the following errors:
contentType: "application/json; charset=utf-8",
Thank you marteljn.
Enclosing the variables prop
, error
, username
in single codes.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다