Using JSON, passing variable from php to javascript
- by Ryan Fung
I wonder why it is not working?
check_login.php
<?php
session_start();
$data = array("username" => "true");
echo json_encode($data);
?>
my js file
var linkName;
$.ajax({
type: "POST",
url: "check_login.php",
dataType: "json",
success: function(json){
if(json.username != "true")
{
//do something
}
}
});
I am trying to get the username after checking whether or not the user has signed in yet in the php file, something like passing a session variable. But currently passing a string seems to already have a problem. Any know what I did wrong here?
Still not working the code above. Anyone want to help me out here?