Hola, tengo un problema y es que no me sigue el código una vez que no ha encontrado registros.
Es decir no me imprime: html_user = '<tr><td colspan="4" align="center">No se encontraron registros..</td></tr>';
Pongo el código:
[js]
function filtrar()
{
$.ajax({
data: $("#frm_filtro").serialize()+ordenar,
type: "POST",
dataType: "json",
url: "ajax.php?action=listar",
beforeSend:function(){
$('.carga1').css('display','block');
$('.carga1').html("<img src='imagenes_menu/ajax-loader4.gif' align='center' /><br />Cargando...");
},
complete: function() {
$(".carga1").show();
$(".carga1").hide();
},
success: function(data){
var html_user ='' ;
if(data.length > 0){
$.each(data, function(i,item){
html_user += '<tr ondblclick="pulsar(this, ' + *String.fromCharCode(39) + item.id_aviso + String.fromCharCode(39) *+ ');" >';
html_user += '<td style="'+item.style+'"><input name="demo" type="radio" value="' + item.id_aviso + '"/></td>';
html_user += '<td style="'+item.style+'">'+item.id_aviso+'</td>';
html_user += '<td style="'+item.style+'">'+item.telefonos+'</td>';
html_user += '<td style="'+item.style+'">'+item.name+' '+item.apellidos+'</td>';
html_user += '<td style="'+item.style+'">'+item.calle+'</td>';
html_user += '<td style="'+item.style+'">'+item.localidad+'</td>';
html_user += '</tr>';
});
}
//////////// A partir de aquí es donde no hace nada
if(html_user == '')
html_user = '<tr><td colspan="4" align="center">No se encontraron registros..</td></tr>';
$("#data tbody").html(html_user);
$('.carga').html('');
if(data.length=='0'){
var telefonos = document.getElementsByName('telefonos');
if (confirm("¿Nuevo Cliente?")) {
if (document.form12.telefonos.value=="")
{
alert("¡Ingrese nº de teléfono!");
document.form12.telefonos.focus; // posicionas el puntero en ese campo
return false;//le dices q no envie nada
}
document.forms['form12'].submit();
} else {
return false;
}
}
}
});
}
[/js]
Gracias y un saludo.
No me sigue el código si no encuentra registros.
Comenzado por
madri09
, feb 22 2013 01:51
3 respuestas en este tema
#1
Escrito 22 febrero 2013 - 01:51
#2
Escrito 22 febrero 2013 - 04:40
podrías hacer un
echo $html_user;?
antes del if $html_user = ''? y decirnos que imprime?
echo $html_user;?
antes del if $html_user = ''? y decirnos que imprime?
#3
Escrito 22 febrero 2013 - 04:47
Hola poliburro, no puedo me da error de sintaxis en esa línea:
});
}
echo $html_user;
if(html_user == '')
html_user = '<tr><td colspan="4" align="center">No se encontraron registros..</td></tr>';
$("#data tbody").html(html_user);
$('.carga').html('');
#4
Escrito 28 febrero 2013 - 03:37
Siento que tienes un problema en las comillas...
Pero si no nos dices la linea en especifico que te arroja el error pues ¡como te podemos ayudar?
Pero si no nos dices la linea en especifico que te arroja el error pues ¡como te podemos ayudar?