1
In a query I do in Mongodb using Ajax and PHP, when I manipulate Objectid already in javascript, it returns me as [Object Object]. How do I use it as a string?
It follows code $.ajax()
$.ajax({
url: 'funcoes/registroeventos.php',
data: {
"ref": ref
},
type: 'post',
dataType: 'json',
cache: false,
beforeSend: function (xhr) {
},
error: function (jqXHR, textStatus, errorThrown) {
},
success: function (dados) {
$.each(dados, function () {
$.each(this, function (index, value) {
alert(value);
});
});
}
});
Follow the PHP code:
$ref = $_POST['ref'];
try {
$consulta = ['ref' => $ref, 'excluido' => 'n'];
$opcoes = [];
$query = new MongoDB\Driver\Query($consulta, $opcoes);
$linhas = $conexao->executeQuery($bd . "maquinas", $query);
echo json_encode(iterator_to_array($linhas));
} catch (Exception $exc) {
echo $exc->getTraceAsString();
}
Example of Json
:
[
{"_id":{"$oid":"5aafac02dc32b7f93a3fda00"}, "ref":"DIP001",
"nome":"Dip Tork", "status":"setup", "excluido":"n",
"idsetor":"5aafaba2dc32b7f93a3fd9ff"}
]
Take the example of Javascript
– novic
You mean the json? [{"_id":{"$oid":"5aafac02dc32b7f93a3fda00"}, "ref":"DIP001", "name":"Dip Tork", "status":"setup", "excluded":"n", "idsector":"5aafaba2dc32b7f93a3fd9ff"} ]
– Diego de Lima
That you can’t get the value?
– novic
I tried to access it in several ways. But it always returns me as [Object Object]. All other values it returns normal. But the Objectid always as Object.
– Diego de Lima
I made an example on that
json
of the commentary !!!– novic