0
I have the following function:
function novasMensagens(Alerta) {
var retorno = Alerta > 0 ? Alerta : "";
return retorno;
}
document.getElementById("msgNumero").innerHTML = novasMensagens();
Now I intend to return the value of Alerta
of the above function by ajax of a query.
File php
where I consult:
$query = "SELECT COUNT(A.Alertas) AS Alerta
FROM(
SELECT Id, De, Assunto, Conteudo, Prioridade, TIME_FORMAT(Recebido,'%h:%i') AS Hora, DATE(Recebido) AS Data,
Email, Tipo, centrodb.Alertas.Para, Status, Count(Status) AS Alertas FROM centrodb.Alertas LEFT OUTER JOIN centrodb.ValAlertas
ON centrodb.ValAlertas.IdSMS = centrodb.Alertas.Id AND centrodb.ValAlertas.Para = centrodb.Alertas.Para
WHERE centrodb.Alertas.Para = 'Pedro'
Group BY Id, De, Assunto, Conteudo, Prioridade, Recebido, Email, Tipo, centrodb.Alertas.Para, Status) AS A
WHERE A.Alertas = '0'
LIMIT 10";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_array($result);
echo json_encode($row);
In the above function I added ajax as follows:
function novasMensagens(Alerta) {
var retorno = Alerta > 0 ? Alerta : "";
return retorno;
$.ajax({
type: 'GET',
url : './fetchbusca',
success : function(data) {
console.log(json);
}
});
}
document.getElementById("msgNumero").innerHTML = novasMensagens();
But nothing returns in json
The value that will return on json
, I have to assign it to Alerta
, that is within the variable retorno
.
was what I needed. Now I have only one doubt, the value that is returned within the Success function, is assigned above to the
Alerta
that is within the variableretorno
?– Bruno
Unless you do this assignment within Success, it will not be assigned
– JrD
do it this way:
var Alerta = data;
– Bruno