Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Mandar parametros por AJAX

Estas en el tema de Mandar parametros por AJAX en el foro de Frameworks JS en Foros del Web. Primero que todo Feliz año para todos!! Tengo una página que es un autocompletar....donde se escribe la descripcion de un producto, tengo un combobox que ...
  #1 (permalink)  
Antiguo 30/12/2009, 15:46
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 16 años, 7 meses
Puntos: 0
Mandar parametros por AJAX

Primero que todo Feliz año para todos!!

Tengo una página que es un autocompletar....donde se escribe la descripcion de un producto, tengo un combobox que permite filtrar "con o sin stock" y ahi está el problema, no logro recibir los dos parámetros...solo el de descripcion funciona
Este es el codigo:

selectusuarios.asp
Código ASP:
Ver original
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html xmlns="http://www.w3.org/1999/xhtml"lang="es" xml:lang="es">
  3. <head>
  4. <meta name="http-equiv" content="Content-type: text/html; charset=UTF-8"/>
  5. <STYLE TYPE="text/css">
  6. #contenedor div.seleccionado {font-weight:bold; background:#F0F0F0; color:#black;}
  7. #contenedor div.deseleccionado {background:#FFFFFF; color:#000000;}
  8. #contenedor div{font:11px verdana; color:#000000; cursor:pointer;
  9. var obj = document.getElementById("contenedor");
  10.    
  11.         if (ajax.readyState==1 || ajax.readyState==2 || ajax.readyState==3) {
  12.                                         obj.innerHTML = "<p align='center'><img src='../images/cargando.gif' border='0px' widht='15px' height='15px'/></p>";
  13.             obj.style.display= "block";
  14.                 }
  15.  
  16.                 else if (ajax.readyState==4) {
  17.             if (ajax.status==200) {
  18.             obj.innerHTML = unescape(ajax.responseText);
  19.  
  20.             }else {
  21.                                     obj.innerHTML = "<p>Se ha producido un error</p>";
  22.             }
  23.  
  24.         if (obj.style.display == "none")  obj.style.display= "block";
  25.         }
  26. },
  27.  
  28. Seleccionar: function () {
  29. var ref = document.getElementById(this.id).getElementsByTagName('DIV');
  30. //alert(ref);
  31. for (var i = 0; i < ref.length; i++) {
  32.  
  33. SelUsuario.Evento(ref[i], 'click', function() {
  34. SelUsuario.Pegar(this.id);
  35. //alert(this.id);
  36. })  
  37.  
  38. SelUsuario.Evento(ref[i], 'mouseover',  function() {
  39. SelUsuario.Marcar(this.id);
  40. })
  41.  
  42. //SelUsuario.Evento(ref[i], 'mouseout',  function() {
  43. //SelUsuario.DesMarcar(this.id);
  44. //})
  45. }
  46. }
  47.  
  48. Pegar: function (valor) {
  49. //alert("el val " +valor);
  50. var obj = document.getElementById("contenedor")
  51.         document.getElementById("txt").value = valor;
  52.                 if (obj.style.display == "block"); obj.style.display= "none";      
  53. },
  54.  
  55. Pegar2: function (ev) {
  56. var obj = document.getElementById("contenedor")
  57. var ref = obj.getElementsByTagName('DIV');
  58. var keyCode = document.layers ? ev.which : document.all ? event.keyCode : document.getElementById ? ev.keyCode : 0;
  59.  
  60. // enter 13 tab 9
  61. if ((keyCode == 13) || (keyCode == 9)) {
  62. //alert("enter")
  63.  
  64. for (var i = 0; i <= ref.length-1; i++) {
  65. if (ref[i].className == "seleccionado") {
  66.  
  67.         document.getElementById("txt").value = ref[i].id;
  68.         //window.focus();
  69.         if (obj.style.display == "block"); obj.style.display= "none";
  70. break;
  71. //alert(ref[i].id);
  72.  
  73. }
  74. }
  75.  
  76. if (keyCode == 13) {
  77.     try{ // DOM;
  78.         ev.preventDefault();
  79.         }catch(e){ // iexplore;
  80.         ev.returnValue = false;
  81.         }
  82. }
  83.  
  84. }  
  85. },
  86.  
  87. BajaOpt: function() {
  88. var ref = document.getElementById("contenedor").getElementsByTagName('DIV');
  89. for (var i = 0; i <= ref.length-1; i++) {
  90. if (ref[i].className == "seleccionado") {
  91. ref[i].className = "deseleccionado";
  92. if (i < ref.length-1){
  93. i++;
  94. }else{
  95. i = 0;
  96. }
  97. //alert("Largo: " +(ref.length-1)+ " Valor: " +i);
  98. ref[i].className = "seleccionado"
  99. }
  100. }
  101. },
  102.  
  103. SubeOpt: function() {
  104. var ref = document.getElementById("contenedor").getElementsByTagName('DIV');
  105. for (var i = 0; i <= ref.length-1; i++) {
  106. if (ref[i].className == "seleccionado") {
  107. ref[i].className = "deseleccionado";
  108. if (i < ref.length && i > 0){
  109. i--;
  110. }else{
  111. i = ref.length-1;
  112. }
  113. //alert("Largo: " +(ref.length-1)+ " Valor: " +i);
  114. ref[i].className = "seleccionado"
  115. }
  116. }
  117. },
  118.  
  119. Marcar: function (id) {
  120. var selecionado = document.getElementById(id);
  121. var ref = document.getElementById("contenedor").getElementsByTagName('DIV');
  122. for (var i = 0; i <= ref.length-1; i++) {
  123. if (ref[i].id != id) {
  124. ref[i].className = "deseleccionado";
  125. selecionado.className = "seleccionado";
  126. }
  127. }
  128. },
  129.  
  130. Cerrar: function () {  
  131. var obj = document.getElementById("contenedor")
  132.             if (obj.style.display == "block"); obj.style.display= "none";    
  133. }
  134. }
  135.  
  136. SelUsuario.Evento(window, 'load', SelUsuario.init);
  137. </script>
  138. </head>
  139. <body>
  140. <form method="post" action="">
  141. Nombre Usuario: <input name="txt" type="text" id="txt" tabindex="1" value="" size="40" autocomplete="off" />
  142. <div class="vink" style="margin:5px 0px 0px 10px">
  143. <div id="contenedor" class="capa" style="display:none;"></div></div>
  144. Filtrar: <select id="stock" name="stock">
  145.          <option selected>Solo con Stock</option>
  146.          <option>Sin Stock</option>
  147.           </select>
  148. <div class="vink" style="margin:5px 0px 0px 10px">
  149. <div id="stock" class="capa" style="display:none;"></div></div>
  150. <input type="submit" value="Enviar">
  151. </form>
  152. </body>
  153. </html>

SelecUsuarios.asp
Código ASP:
Ver original
  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
  2. <%
  3. Response.addHeader "pragma", "no-cache"
  4. Response.CacheControl = "Private"
  5. Response.Expires = -1000
  6. %>
  7. <%
  8.  
  9. usuario = CStr(Request.QueryString("q"))
  10. combox = CStr(Request.QueryString("variable"))
  11. response.write ("'"&combox&"'")
  12.  
  13. IF Len(usuario) >= 2 then
  14.  
  15. set Cnn = Server.CreateObject("ADODB.Connection")
  16. set rs = Server.CreateObject ("ADODB.Recordset")
  17. Cnn.Open Session("cnx")
  18.  
  19. SQL="Select descrip FROM Producto WHERE descrip LIKE '"&usuario&"%' and stock >0 ORDER BY Descrip asc"
  20. set rs = Cnn.Execute(SQL)
  21. If not rs.eof then
  22. registros = rs.getrows()
  23.             Else
  24.             Response.Write "<p class=""deseleccionado""><strong>Sin resultados</strong></p>"
  25.             Response.End ()
  26.         End If
  27.     rs.Close
  28.     set rs = nothing
  29.     Cnn.Close
  30.     set Cnn = nothing
  31. END IF
  32.  
  33. For i = 0 to Ubound(registros,2)
  34. If i = 0 then
  35. Response.Write "<div id="""& registros(nombre,i) &""" class=""seleccionado"">"& ResaltarSubStr(registros(nombre,i)) & "</div>"
  36. Else
  37. Response.Write "<div id="""& registros(nombre,i) &""" class="""">" & ResaltarSubStr(registros(nombre,i)) & "</div>"
  38. End If
  39. Next
  40.  
  41.  
  42. Function ResaltarSubStr(texto)
  43. Dim objRegExp
  44.  
  45.     Set objRegExp= New RegExp
  46. objRegExp.IgnoreCase = True
  47.  
  48. objRegExp.Pattern = "\b("&usuario&")+(\w)"
  49. texto = objRegExp.Replace(texto, "<strong>$1</strong>$2")
  50.  
  51. Set objRegExp = Nothing
  52. ResaltarSubStr = texto
  53.  
  54. End Function
  55.  
  56. %>

Eso seria...
De antemano muchas gracias

Última edición por darkmcloud; 30/12/2009 a las 19:52
  #2 (permalink)  
Antiguo 01/01/2010, 20:45
Avatar de jackson666  
Fecha de Ingreso: noviembre-2009
Ubicación: Buenos Aires, Argentina
Mensajes: 1.971
Antigüedad: 14 años, 6 meses
Puntos: 65
Respuesta: Mandar parametros por AJAX

Si este es tal cual el codigo que tenes, aca hay un error grave:

Código HTML:
Ver original
  1. <STYLE TYPE="text/css">
  2. #contenedor div.seleccionado {font-weight:bold; background:#F0F0F0; color:#black;}
  3. #contenedor div.deseleccionado {background:#FFFFFF; color:#000000;}
  4. #contenedor div{font:11px verdana; color:#000000; cursor:pointer;
  5.  
  6. var obj = document.getElementById("contenedor");

Tenes "embebido" javascript en css....

Por otro lado, como haces para hacer la peticion asincrona? No veo ningun evento en ningun lado...
__________________
HV Studio
Diseño y desarrollo web
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 09:58.