I need to return an array in php and use it in javascript. When I print the returned value it prints empty string. How do I make mistake?
$.ajax({
type: "POST",
url: "sort2.php",
success: function(result){
alert(result[0]);
}
});
//sort2.php
$data[0] = "book";
$data[1] = "pen";
$data[2] = "school";
echo json_encode($data);