Jump to content


Photo

No me sigue el código si no encuentra registros.


  • Please log in to reply
3 replies to this topic

#1 madri09

madri09

    Advanced Member

  • Miembros
  • PipPipPip
  • 72 posts

Posted 22 February 2013 - 01:51 PM

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.
  • 0

#2 poliburro

poliburro

    Advanced Member

  • Administrador
  • 4945 posts
  • LocationMéxico

Posted 22 February 2013 - 04:40 PM

podrías hacer un

echo $html_user;?

antes del if $html_user = ''? y decirnos que imprime?


  • 0

#3 madri09

madri09

    Advanced Member

  • Miembros
  • PipPipPip
  • 72 posts

Posted 22 February 2013 - 04:47 PM

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('');
   

  • 0

#4 porfi.dev

porfi.dev

    Advanced Member

  • Miembros
  • PipPipPip
  • 183 posts
  • LocationMy House @ México

Posted 28 February 2013 - 03:37 PM

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?
  • 0




IP.Board spam blocked by CleanTalk.