在jquery mobile中获取php会话值

Am creating a page in jquery mobile whereby a jquery function is supposed to check for the set php session variable but i get an error of syntax error in the console.

The code:

$(document).on("pageshow","#schoolperformance", function(){ 

var sessName = '<?php echo json_encode($_SESSION['schoolname']); ?>';

 alert(sessName);

});

When i check the value of $_SESSION['schoolname'] in a normal way via a raw php script it returns a value of the session.

THE FILE IS A JAVASCRIPT FILE that is saved as a .js file

Change the single quote at this line

var sessName = '<?php echo json_encode($_SESSION['schoolname']); ?>';

To double quotes

var sessName = "<?php echo json_encode($_SESSION['schoolname']); ?>";

The sessName variable string is breaking up by using single quotes surrounding the string and php variable. because its stops right at ['

UPDATE:

As you say in your comments that you trying to perform PHP in .JS files that is totally wrong, because for PHP to work you need to use .PHP file extensions not .JS extensions