I have a Json file in the server:
file.json :
{"max":"512", "min":"1", ...
I get it with an ajax call:
$.ajax({
url: 'load_json.php',
type: "POST",
data: { id: id },
dataType: 'json',
success: function(resp) {
console.log(resp.json.max);
}
});
Where load_json.php is:
$json = file_get_contents("file.json");
$response = array('json' => $json);
echo json_encode($response);
But in the console I get undefined. Why?
A possible solution is:
$response = array('json' => json_decode($json));
Is this the most effective solution?