Foros del Web » Programando para Internet » Jquery »

problema para mostrar busquedas en mi buscador ajax

Estas en el tema de problema para mostrar busquedas en mi buscador ajax en el foro de Jquery en Foros del Web. Hola amigas y amigos,, veran tengo un problema con un codigo que tengo. Intento hacer un buscador que nada mas meter una letra en el ...
  #1 (permalink)  
Antiguo 02/03/2016, 16:15
 
Fecha de Ingreso: mayo-2012
Mensajes: 760
Antigüedad: 12 años
Puntos: 5
problema para mostrar busquedas en mi buscador ajax

Hola amigas y amigos,, veran tengo un problema con un codigo que tengo.


Intento hacer un buscador que nada mas meter una letra en el input me muestra palabras que la contengan de manera automatica con ajax.

Y creo que todo esta bien pero en mi archivo llamado: "222---script.js" me dice:

var dato , esta "unused", osea que no esta siendo usada esa variable y claro deberia hacerlo.

Miren este es el codigo:

archivo 1 llamado: "222---index_form_buscador_post_bbddarray_json.php":

Código HTML:
Ver original
  1. <!DOCTYPE html>
  2.  
  3. <html lang="es">
  4.    
  5.     <head>
  6.             <meta charset="utf-8" />
  7.             <title>Buscador ajax + jquery + php</title>          
  8.     </head>
  9.    
  10.    
  11.    
  12.     <body>
  13.  
  14.         <h1>Buscador ajax + jquery + php</h1>
  15.  
  16.         <form>
  17.            
  18.             <input type="buscador" name="buscador" id="buscador" placeholder="Nombre o Info" />
  19.        
  20.         </form>
  21.            
  22.        
  23.  
  24.         <div id="elresultado"></div>
  25.        
  26.        
  27.        
  28.         <script type="text/javascript" src="jquery-1.10.1.min.js"></script>
  29.         <!--<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>-->
  30.         <script src="222---script.js"></script>
  31.    
  32.     </body>
  33.  
  34. </html>



archivo 2 llamado "222---script.js"; (que aqui es donde esta la variable no usada)

Código Javascript:
Ver original
  1. $('#buscador').keyup(function()
  2.  
  3. {
  4. var dato = $('#buscador').val();
  5.  
  6. //Expresion regular que ignora mayusculas o minusculas
  7. var myExp = new RegExp(dato_a_buscar, 'i');
  8.  
  9.  
  10. //$.getJSON('2---data.php?callback=?', function(dato)
  11. $.getJSON('222---data.json', function(dato)
  12.  
  13. {
  14. var salida = '<ul>';
  15.  
  16. $.each(dato, function(clave, valor)
  17.  
  18. {
  19.  
  20. if((valor.name.search(myExp) != -1))
  21.  
  22. {
  23. salida +='<li>';
  24. salida +='<h2>' + valor.name + '</h2>';
  25. //salida +='<img src="images/' + valor.shortname + '_tn.jpg" alt="'+ valor.name +'" />';
  26. //salida +='<p>' + valor.bio + '</p>';
  27. salida +='</li>';
  28. }
  29. });
  30.  
  31.  
  32. salida += '</ul>';
  33.  
  34.  
  35. $('#elresultado').html(salida);
  36. });
  37. });



archivo 3 llamado "222---data.json";

Código json:
Ver original
  1. [
  2. {
  3. "name":"Barot Bellingham",
  4. "shortname":"Barot_Bellingham",
  5. "reknown":"Royal Academy of Painting and Sculpture",
  6. "bio":"Barot has just finished his final year at The Royal Academy of Painting and Sculpture, where he excelled in glass etching paintings and portraiture. Hailed as one of the most diverse artists of his generation, Barot is equally as skilled with watercolors as he is with oils, and is just as well-balanced in different subject areas. Barot's collection entitled 'The Un-Collection' will adorn the walls of Gilbert Hall, depicting his range of skills and sensibilities - all of them, uniquely Barot, yet undeniably different"
  7. },
  8. {
  9. "name":"Jonathan G. Ferrar II",
  10. "shortname":"Jonathan_Ferrar",
  11. "reknown":"Artist to Watch in 2012",
  12. "bio":"The Artist to Watch in 2012 by the London Review, Johnathan has already sold one of the highest priced-commissions paid to an art student, ever on record. The piece, entitled Gratitude Resort, a work in oil and mixed media, was sold for $750,000 and Jonathan donated all the proceeds to Art for Peace, an organization that provides college art scholarships for creative children in developing nations"
  13. }
  14.  
  15. ]


gracias de antemano.

Etiquetas: ajax, buscador, busquedas
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 03:23.