How can i send json data from php to javascript?

To send JSON data from PHP to JavaScript, you need to use the json_encode() function.

Example:


  $data = array('name' => 'John', 'age' => 30);
  echo json_encode($data);
  

Beginner's Guide to PHP