0
Hello!
Can someone tell me what’s wrong ?
Using the filter function, I am seeing a Undefined return.
Javascript
var enum_toastr_type = {
success: 1,
info: 2,
warning: 3,
error: 4
}
/***# PAGELOAD START #***/
$(document).ready(function() {
toastr.options = {
progressBar: true,
closeButton: false,
positionClass: 'toast-bottom-right',
timeOut: '20000'
}
/*
var visited = localStorage.getItem('visited');
if(!visited) {
setTimeout('get_mensagem_ajax()', 50);
localStorage.setItem('visited', true);
}
*/
setTimeout('get_mensagem_ajax()', 50);
});
/***# PAGELOAD END #***/
/*** Métodos Início ***/
function exibe_mensagem(mensagens) {
var msg = mensagens.filter(function(x) {
return x;
});
exibe_mensagem_toastr(msg);
}
function exibe_mensagem_toastr(mensagens) {
$(mensagens).each(function() {
//console.log(this.mensagem);
switch (this.tipo_notificacao) {
case enum_toastr_type.info:
toastr.info(this.mensagem);
break;
case enum_toastr_type.success:
toastr.success(this.mensagem);
break;
case enum_toastr_type.warning:
toastr.warning(this.mensagem);
break;
case enum_toastr_type.error:
toastr.error(this.mensagem);
break;
}
});
}
/*** Métodos Fim ***/
/***# AJAX START #***/
function get_mensagem_ajax() {
$.ajax({
type: 'GET',
contentType: 'application/json; charset=utf-8',
url: 'notificacao/get_mensagem',
success: (function(data) {
exibe_mensagem(data);
}),
error: (function(erro) {
trata_erro_ajax(erro);
})
});
}
/*** AJAX END ***/

tries so $(messages). filter
– aa_sp
It didn’t work either
– Wagner Fillio
Have you seen if $(messages) or messages are returning anything? It may no longer be found. if you can, post your html too
– aa_sp
Both are returning and displaying the array as per image, but when will I check the
this, in functionexibe_mensagem_toastrhave Undefined.– Wagner Fillio
got it, so let’s try another try: $(messages). each(Function(i, item) {.... and then try to access: item.type_notification
– aa_sp
Try adding the index
[1]in the variable:$(mensagens[1]).each(function() {– Sam
Yes, with the index I can, but I found the problem,the problem is in Enum, which expected the type
INT, but it was coming withstring, fixed the return on the server and worked smoothly. Thank you very much– Wagner Fillio