I was trying to grab an encoded array [{"got":"1235.00","needed":"4350"}]
from a file using this code:
function getNewValues(){
$.ajax({
dataType: 'json',
url: 'get.php',
type: 'POST',
cache: false
})
.success(function(data) {
return data;
})
.fail(function() {
console.log("An error ocurred");
})
}
But the problem is that the only thing i get back in the return data
is array( object )
, the problem is that i dont know whats wrong or in wich file it went wrong.
generating the encoded array:
<?php
$pdo = new PDO('mysql:host=127.0.0.1;dbname=thermometer', 'root', '');
$sql = 'SELECT `got`.`value` AS got, `needed`.`value` AS needed FROM `needed`, `got`';
$statement = $pdo->prepare($sql);
$statement->execute();
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
$json = json_encode($result);
print_r($json);
?>
It would be nice if someone has an solution for this becouse i cant solve it :(