0
I am modifying a very old system panel and need to add a new div and set a color according to the return of ajax .
setInterval('carregarProximo()', 3000);
function carregarProximo(){
//$("#id_chamada").load(baseUrl+"/chamada/buscar-chamadas/");
var som = new Audio(baseUrl+'/public/sounds/dingdong.wav');
$.ajax({
url: baseUrl+"/chamada/buscar-chamadas/",
type: "GET",
success:function(txt){
for(var i in txt){
if(i == 0){
if(txt[i].cha_status == "C"){
/* $.ajax({
url: baseUrl+"/chamada/ler",
type: "POST",
data: {
usu_nome: "teste"
},
success: function(txt){
alert(txt);
var sound = $("<embed id='sound' type='audio/mpeg' />");
sound.attr('src', txt);
sound.attr('loop', false);
sound.attr('hidden', true);
sound.attr('autostart', true);
$('body').append(sound);
}
});*/
som.play();
alteraStatus(txt[i].age_codigo);
}
var conteudo = "<div id=\"div_superior\">"+
"<b>"+txt[i].age_paciente+"</b>"+
"</div>"+
"<div id=\"div_setor\">"+
"<b>"+txt[i].set_nome+"</b>"+
"</div>"+
"<div>"+
+"</div>"
"<div >"+
"</div>";
}else {
switch(txt[i].cor){
case "red":
$("#cor").css('background-color', 'red');
break;
case "GoldenRod":
$("#cor").css('background-color', "GoldenRod");
break;
case "yellow":
$("#cor").css('background-color', "yellow");
break;
case "green":
$("#cor").css('background-color', "green");
break;
case "blue":
$("#cor").css('background-color', "blue");
break;
}
conteudo += "<div class=\"anterior_1\">"+
"<br/>"+
//<?=$this->abreviaNome($chamada[age_paciente],24)?>
txt[i].age_paciente+
"<br/>"+
"<div id=\"cor\" style='width: 100px'>"+
"</div>"+
"<br/>"+
"<font color=\"red\"><b>"+txt[i].set_nome+"</b></font>"+
"</div>";
}
//echo $this->action("altera-status", "chamada", "default", array("age_codigo" => $chamada[age_codigo]));
// txt[i].cor+
}
//alert(conteudo);
$("#id_chamada").html(conteudo);
}
});
}
function alteraStatus(age_codigo){
$.ajax({
url: baseUrl+"/chamada/altera-status/",
data: {
age_codigo:age_codigo},
type: "GET",
success:function(txt){
}
});
}
Then as shown in the code I created a div, gave its name as color and tried to assign a backgrond with Jquery. I don’t know if my clause is wrong or the syntax of the code itself. I even tested this "txt.[i]. color" and it returned the correct corrections.
Function of ajax :
public function buscarChamadas($uni_codigo=FALSE){
$where = $this->select()
->setIntegrityCheck(FALSE)
->from(array("cha"=>"chamada"),array("age_codigo","cha_status","cha_codigo"))
->join(array("age"=>"agendamento"),"age.age_codigo=cha.age_codigo","age_paciente")
->join(array("log"=>"logon"),"log.id_login=cha.usr_codigo","")
->join(array("set"=>"setor"),"set.set_codigo=log.cod_setor","set_nome")
->joinLeft(array("pre"=>"pre_consulta"),"pre.age_codigo=age.age_codigo",array("cor"=>"(CASE WHEN pc_clas_risco=1 THEN 'red' WHEN pc_clas_risco=2 THEN 'GoldenRod' WHEN pc_clas_risco=3 THEN 'yellow' WHEN pc_clas_risco=4 THEN 'green' WHEN pc_clas_risco=5 THEN 'blue' END)"))
->where("age.uni_codigo =?",$uni_codigo)
->order("cha_status")
->order("cha.cha_codigo DESC")
->limit(6);
// die($where);
// $sql = $where;
// die($sql);
return $this->fetchAll($where);
}
A Console.log was placed after the Else "console.log(txt[i].cor)" switch... And also a b tag inside the color given div.For content presentation.
good, day man, what is the return of the function ? how is it returning ?
– Joan Marcos
With the addition of the photo helped ?
– Lucas Alves
Will you change the color of what is inside (content += "...) correct ? if that’s the case the order is wrong, I think you running the case before it takes the reference of the element created in the DOM,
– Joan Marcos
Why is div and the other elements you are creating like this <div id="color " ? with id = "color" ?
– Joan Marcos
What you said about case this right there is no way I change the color being that the div doesn’t even exist . So the output should be another then ?. So before I started working on this panel it was already like this so I kept it to not give problems you deem unnecessary ?
– Lucas Alves