Why my php code was missing after I deployed onto web hosting?

I had this javascript code to get data from php code

var data = <?php echo json_encode($data); ?>; 

It worked ok when I was using xampp on my computer.
But after I deployed my project onto web hosting, it turned to

var data = '';

The php code disappeared.
Why did it happen and how to resolve it?
Thanks!