Foros del Web » Programando para Internet » Jquery »

Dar estilo a una funcion ajax

Estas en el tema de Dar estilo a una funcion ajax en el foro de Jquery en Foros del Web. Hola, por favor a ver si podeis ayudarme. Tengo esta funcion y lo que quiero es darle estilo a las filas donde estan los item ...
  #1 (permalink)  
Antiguo 20/04/2013, 13:02
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 8 meses
Puntos: 10
Dar estilo a una funcion ajax

Hola, por favor a ver si podeis ayudarme. Tengo esta funcion y lo que quiero es darle estilo a las filas donde estan los item que me imprime, pero no me sale.

Código Javascript:
Ver original
  1. function filtrar()
  2.  
  3. {
  4.      
  5.          $.ajax({
  6.          data: $("#frm_filtro").serialize()+ordenar,
  7.          type: "POST",
  8.          dataType: "json",
  9.          url: "ajax_mobile.php?action=listar",
  10.          beforeSend:function(){
  11.         $('.carga1').css('display','block');
  12.         $('.carga1').html("<img src='imagenes_menu/ajax-loader4.gif' align='center' /><br />Cargando...");
  13.         },  
  14.         complete: function() {
  15.  
  16.             $(".carga1").show();
  17.  
  18.             $(".carga1").hide();
  19.  
  20.         },            
  21.         success: function(data){
  22.         var html_user ='' ;
  23.         if(data.length > 0){
  24.         $.each(data, function(i,item){
  25.  
  26.  html_user += '<ul data-role="listview" data-inset="true" >';
  27.  html_user += '<li data-role="list-divider" role="heading">'+item.recambio+'<span class="ui-li-count">Stock:</span></li>';
  28.  html_user += '<li data-theme="c">';
  29.  html_user += '<a href="#">';
  30.  html_user += '<h4>'+item.denominacion+'</h4>';
  31.  html_user += '       <p>Lorem ipsum</p>';
  32.  html_user += '    <span class="ui-li-count">1</span>';
  33.  html_user += '   <p class="ui-li-aside">Aside</p>';
  34.  html_user += '   </a><a href="#">Pvp:'+item.pvp+'</a></li>';
  35.  html_user += ' </ul>';
  36.                          
  37.         });                    
  38.     }
  39.     if(html_user == '')
  40.     html_user = '<tr><td colspan="4" align="center">No se encontraron registros..</td></tr>';
  41.     $("#data tbody").html(html_user);

Gracias
  #2 (permalink)  
Antiguo 20/04/2013, 13:53
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Dar estilo a una funcion ajax

Puedes agregarle estilos en línea (con el atributo style) o simplemente colocarle una clase a los elementos y usar una hoja de estilos para darle el estilo que quieras.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #3 (permalink)  
Antiguo 20/04/2013, 14:04
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 8 meses
Puntos: 10
Respuesta: Dar estilo a una funcion ajax

Gracias David, pero como ves ya les estoy dando clase, pero no sale.

Código Javascript:
Ver original
  1. html_user += '<ul data-role="listview" data-inset="true" >';
  2.  html_user += '<li data-role="list-divider" role="heading">'+item.recambio+'<span class="ui-li-count">Stock:</span></li>';
  3.  html_user += '<li data-theme="c">';
  4.  html_user += '<a href="#">';
  5.  html_user += '<h4>'+item.denominacion+'</h4>';
  6.  html_user += '       <p>Lorem ipsum</p>';
  7.  html_user += '    <span class="ui-li-count">1</span>';
  8.  html_user += '   <p class="ui-li-aside">Aside</p>';
  9.  html_user += '   </a><a href="#">Pvp:'+item.pvp+'</a></li>';
  10.  html_user += ' </ul>';
  #4 (permalink)  
Antiguo 20/04/2013, 14:06
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Dar estilo a una funcion ajax

¿Y en tu hoja de estilos tienes las referencias a esas clases?
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #5 (permalink)  
Antiguo 20/04/2013, 14:15
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 8 meses
Puntos: 10
Respuesta: Dar estilo a una funcion ajax

Pero el estilo lo hacen los enlaces de jquery no? Te pongo el cod:

Código Javascript:
Ver original
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Aplic. Web de jQuery Mobile</title>
  6. <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.css" />
  7. <script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
  8. <script src="http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.js"></script>
  9. <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1-rc.1/jquery.mobile-1.1.1-rc.1.min.css" />
  10. <script src="js/jquery-1.7.1.min.js"></script>
  11. <script src="js/jquery.mobile-1.1.1-rc.1.min.js"></script>
  12. <script>
  13. function filtrar()
  14.  
  15. {
  16.      
  17.          $.ajax({
  18.          data: $("#frm_filtro").serialize()+ordenar,
  19.          type: "POST",
  20.          dataType: "json",
  21.          url: "ajax_mobile.php?action=listar",
  22.          beforeSend:function(){
  23.         $('.carga1').css('display','block');
  24.         $('.carga1').html("<img src='imagenes_menu/ajax-loader4.gif' align='center' /><br />Cargando...");
  25.         },  
  26.         complete: function() {
  27.  
  28.             $(".carga1").show();
  29.  
  30.             $(".carga1").hide();
  31.  
  32.         },            
  33.         success: function(data){
  34.         var html_user ='' ;
  35.         if(data.length > 0){
  36.         $.each(data, function(i,item){
  37.  
  38.  html_user += '<ul data-role="listview" data-inset="true" >';
  39.  html_user += '<li data-role="list-divider" role="heading">'+item.recambio+'<span class="ui-li-count">Stock:</span></li>';
  40.  html_user += '<li data-theme="c">';
  41.  html_user += '<a href="#">';
  42.  html_user += '<h4>'+item.denominacion+'</h4>';
  43.  html_user += '       <p>Lorem ipsum</p>';
  44.  html_user += '    <span class="ui-li-count">1</span>';
  45.  html_user += '   <p class="ui-li-aside">Aside</p>';
  46.  html_user += '   </a><a href="#">Pvp:'+item.pvp+'</a></li>';
  47.  html_user += ' </ul>';
  48.                          
  49.         });                    
  50.     }
  51.     if(html_user == '')
  52.     html_user = '<tr><td colspan="4" align="center">No se encontraron registros..</td></tr>';
  53.     $("#data tbody").html(html_user);
  54.     $('.carga').html('');
  55. </script>
  56. </head>
  57. <body>
  58.  
  59.  
  60.  
  61.     <div id="principal" data-role="page" data-theme="b" >
  62.  
  63.        
  64.  
  65.         <div data-role="header" data-theme="a">
  66.  
  67.             <h1>Buscar Referencia</h1>
  68.  
  69.             <a href="materialpendiente.php" data-icon="delete" data-iconpos="notext" data-theme="f" data-ajax="false" class="ui-btn-right"></a>
  70.  
  71.         </div>  
  72.  
  73.        
  74.  
  75.         <div data-role="content">
  76.  
  77.         <form id="frm_filtro" method="post" action="menu4.php" name="form12">
  78.  
  79.             <input type="hidden" name ="edTipoReferencia" id="edTipoReferencia" value="" />
  80.  
  81.             <input id="edIdArtFact" name="edIdArtFact" type="hidden" value=""/>
  82.  
  83.                  
  84.  
  85.             <div class="ui-bar-b ui-corner-all ui-shadow" style="padding:1.4em;align:center;">
  86.  
  87.                 <fieldset class="ui-grid-a" >
  88.  
  89.                     <input name="recambio" id="recambio" align="center" type="search" data-theme="b" value="" style="text-transform:uppercase;width:92%"/>
  90.  
  91.                     <button type="button" name="btnfiltrar" id="btnfiltrar" data-theme="b" data-icon="search" value="Buscar">Buscar</button>
  92.  
  93.                 </fieldset>
  94.  
  95.             </div>                  
  96.  
  97.             <br />
  98.  
  99.            
  100.  
  101.             <!--aqui la busqueda-->
  102.          <table id="data">
  103.          <tbody>
  104.          <!--aqui es donde salen las filas-->  
  105.             </tbody>
  106.              </table>      
  107.  
  108.          
  109.                 <!--aqui acaba el script de la busqueda -->
  110.  
  111.             <input name="data1" id="data1" type="hidden" value="" />                    
  112.  
  113.         </form>
  114.  
  115.                 </div>
  116.     </div>
  117.  
  118. </body>
  119.  
  120. </html>
  #6 (permalink)  
Antiguo 20/04/2013, 14:29
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Dar estilo a una funcion ajax

No me había fijado que estabas trabajando con jQuery Mobile, puedes intentar llamando manualmente al método listview() luego de haber insertado la lista:
Código Javascript:
Ver original
  1. $("#data tbody ul").listview();
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #7 (permalink)  
Antiguo 20/04/2013, 14:49
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 8 meses
Puntos: 10
Respuesta: Dar estilo a una funcion ajax

Perdona, pero no sabia donde poner la consulta. Lo he puesto así pero no me saca registros.

Código Javascript:
Ver original
  1. if(html_user == '')
  2.     html_user = '<tr><td colspan="4" align="center">No se encontraron registros..</td></tr>';
  3.     $("#data tbody ul").listview().html(html_user);
  #8 (permalink)  
Antiguo 20/04/2013, 14:51
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Dar estilo a una funcion ajax

Estás intentando llamar al método listview antes de que la lista exista, lo cual no tiene sentido.

Hazlo después de haberlo insertado en el documento.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #9 (permalink)  
Antiguo 20/04/2013, 14:54
Avatar de satjaen  
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 8 meses
Puntos: 10
Respuesta: Dar estilo a una funcion ajax

Si, vuelve a perdonarme:

Código Javascript:
Ver original
  1. if(html_user == '')
  2.     html_user = '<tr><td colspan="4" align="center">No se encontraron registros..</td></tr>';
  3.     $("#data tbody").html(html_user);
  4.     $("#data tbody ul").listview();

Gracias

Etiquetas: ajax, estilo, funcion, html, javascript, js, php
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:13.