What is the best practice for passing multiple data values from PHP to JavaScript using Ajax?
When passing multiple data values from PHP to JavaScript using Ajax, the best practice is to encode the data into a JSON format in PHP and then decode it in JavaScript. This ensures that the data is properly formatted and can be easily accessed in JavaScript.
<?php
// Sample data values
$data1 = "value1";
$data2 = "value2";
$data3 = "value3";
// Encode the data into JSON format
$data = json_encode(array("data1" => $data1, "data2" => $data2, "data3" => $data3));
// Output the JSON data
echo $data;
?>