Example: There is a .js and .php file
The following is written in the .js file:
$.ajax({ url:"index.php", datatype:"json", success:function(result){ console.info(result); } }); In the .php file the following
$array = array("object1" => "Boat","object2" => "Car","object3" => "Ship"); echo json_encode($array); PS If in the .js file in the part of the success block, write this: $objectJson = JSON.parse(result) , then the json string will turn into a json object, then the point was for me to specify datatype: "json" ???