Using JSON, passing variable from php to javascript

Posted by Ryan Fung on Stack Overflow See other posts from Stack Overflow or by Ryan Fung
Published on 2012-09-22T06:13:08Z Indexed on 2012/09/22 21:38 UTC
Read the original article Hit count: 303

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about php

Related posts about JavaScript