Tema: Ajax con ASP
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/12/2009, 14:35
darkmcloud
 
Fecha de Ingreso: octubre-2007
Mensajes: 191
Antigüedad: 16 años, 7 meses
Puntos: 0
Ajax con ASP

compadres de forosdelweb....tengo un problema con un codigo para autocompletar en ASP con Ajax..

Este es el codigo:

Formulario:
Código ASP:
Ver original
  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
  2. <html>
  3. <head>
  4. <script src="clienthint.js"></script>
  5. </head>
  6. <body>
  7. <%
  8. 'this displays the value of the textbox after the form is submitted
  9. If trim(Request("txt1")) <> "" Then
  10.     Response.Write "You entered:"
  11.     Response.Write "<b>" & Request("txt1") & "</b><br /><br />"
  12. End If
  13. %>
  14. <form name="form1" action="clienthint.asp" method="post">
  15. Buscar:
  16. <input type="text" name="txt1" id="txt1" onKeyUp="showHint(this.value,'txt1','form1',true)">
  17. <input type="submit" name="submit" value="Enviar">
  18. </form>
  19. <p>Sugerencias:  <span id="txtHint"></span></p>
  20. </body>
  21. </html>

clienthint.js
Código PHP:
var xmlHttp

function showHint(strboxthisFormautoSubmit)
{
if (
str.length==0)
  { 
  
document.getElementById("txtHint").innerHTML="";
  return;
  }
xmlHttp=GetXmlHttpObject()
if (
xmlHttp==null)
  {
  
alert ("Your browser does not support AJAX!");
  return;
  } 
var 
url="gethint.asp";
url=url+"?q="+str;
url=url+"&b="+box;
url=url+"&f="+thisForm;
url=url+"&a="+autoSubmit;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);


function 
stateChanged() 

if (
xmlHttp.readyState==4)

document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}

function 
GetXmlHttpObject()
{
var 
xmlHttp=null;
try
  {
  
// Firefox, Opera 8.0+, Safari
  
xmlHttp=new XMLHttpRequest();
  }
catch (
e)
  {
  
// Internet Explorer
  
try
    {
    
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (
e)
    {
    
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return 
xmlHttp;
}

//this function allows for Clickable suggestions
function setTextBox(thisText,thisBox,thisForm,autoSubmit){
    
document.getElementById(thisBox).value thisText
    
//this autoSubmits the form after a suggestion is clicked - it is not working :(
    //if(autoSubmit=='true'){
    //    alert(thisForm);
    //    document.getElementById(thisForm).submit();
    //}

Y el archivo ASP que ejecuta la consulta en la base de datos:

gethint.asp
Código ASP:
Ver original
  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
  2. <%
  3. response.expires=-1
  4. Dim rsWords
  5. Dim rsWords_numRows
  6. Dim q
  7. Dim b
  8. Dim hint
  9. q=ucase(request.querystring("q"))
  10. b=(request.querystring("b"))
  11. f=(request.querystring("f"))
  12. a=(request.querystring("a"))
  13. hint=""
  14. Set rsWords = Server.CreateObject("ADODB.Recordset")
  15. rsWords.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("db_hint_words.mdb")
  16. rsWords.Source = "SELECT *  FROM TBL_WORDS  WHERE (word LIKE'" + q + "%') ORDER BY WORD"
  17. rsWords.CursorType = 2
  18. rsWords.CursorLocation = 2
  19. rsWords.LockType = 3
  20. rsWords.Open()
  21. rsWords_numRows = 0
  22.  
  23. If Not rsWords.EOF Then
  24.     Do While Not rsWords.EOF
  25.     'response.write(rsWords.Source)
  26.         If trim(hint) = "" Then
  27.            
  28. hint = "<a href=""javascript:setTextBox('" & rsWords("word") & "','" & b & "','" & f & "','" & a & "');"">" & rsWords("word") & "</a>"
  29.        
  30.         Else
  31.        
  32. hint = hint & " , <a href=""javascript:setTextBox('" & rsWords("word") & "','" & b & "','" & f & "','" & a & "');"">" & rsWords("word") & "</a>"
  33.         End If
  34.         rsWords.MoveNext()
  35.     Loop
  36. End If
  37. if trim(hint)="" then
  38.   response.write("No se han encontrado coincidencias")
  39. else
  40.   response.write(hint)
  41. end if
  42.  
  43. rsWords.Close()
  44. Set rsWords = Nothing
  45. %>

Bueno , lo que pasa es que los resultados los despliega hacia el lado y yo quiero que los despliegue hacia abajo como si fuera una lista desplegable me entienden?

Creo que lo que se debe modificar está en el último archivo, osea el que ejecuta la consulta a la base de datos y muestra los resultados, el gethint.asp

De antemano muchas gracias