2014-10-04 6 views
-2

클래식 ASP를 사용하여 자동 완성 페이지를 만듭니다. 두 개의 다른 페이지, autocomplete.aspsource.asp이 있습니다. 아래 내 코드 :클래식 ASP 자동 완성

autocomplete.asp

<%@ language="VBScript" %> 
<!doctype html> 
<html lang="en"> 
    <head> 
     <meta charset="utf-8"> 
     <title>jQuery UI Autocomplete - Default functionality</title> 
     <link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css"> 
     <script src="//code.jquery.com/jquery-1.10.2.js"></script> 
     <script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script> 
     <link rel="stylesheet" href="/resources/demos/style.css"> 
     <!-- SCRIPT FOR AUTOCOMPETE SEARCH BOX //--> 
     <script type="text/javascript" language="javascript"> 
      $(function() { 
       $("#productname").autocomplete({ 
        source: "source.asp", 
        minLength: 2 
       }); 
      }); 
     </script> 

    </head> 
    <body> 

     <p>&nbsp;</p> 

     <div class="ui-widget"> 
      <label for="tags">Tags: </label> 
      <input id="productname"> 
     </div>  
     <p>&nbsp;</p> 
    </body> 
</html> 

sourse.asp

<%@ language="VBScript" %> 

     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2 /jquery.js" ></script> 
     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js" ></script> 
     <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css"/> 

     <!-- SCRIPT FOR AUTOCOMPETE SEARCH BOX //--> 

    </head> 

    <% 
    Dim keywords, keywords_cmd, output, firstItem 

    Set keywords_cmd = Server.CreateObject ("ADODB.Command") 
    keywords_cmd.ActiveConnection = "DRIVER={SQL Server};SERVER=wsgpdba4.sgp.is.keysight.com;UID=kportal;PWD=q1w2e3r4;DATABASE=A_Sys" 
    keywords_cmd.CommandText = "SELECT ProductId FROM Product where ProductId like '%" & Request.QueryString("term") & "%'" 
    keywords_cmd.Prepared = true 

    Set keywords = keywords_cmd.Execute 

    output = "[" 

    While (NOT keywords.EOF) 
     output = output & "{""ProductId"":""" & keywords.Fields.item("ProductId") & """}," 
     keywords.MoveNext() 
    Wend 

    keywords.Close() 
    Set keywords = Nothing 

    output=Left(output,Len(output)-1) 
    output = output & "]" 
    response.write output 

    %> 
    <body> 

    </body> 
</html> 

source.asp 같은 나를 돌아 :

[{"ProductId":"111 "}]

내가 여기 문제에 100 % 분명 아니지만, JQuery와 UI 컨트롤 값 및 레이블의 예상 형태로 데이터를 가질 필요가

+0

두 번째 코드가 제대로 포맷되지 않은 것 같습니다. 당신은'document','html'과'head' 태그가 빠져있는 것 같습니다 (이것은 당신이 겪고있는 것과 거의 관련이 없습니다). – Paul

답변

-1

도와주세요 :

[{"value":"111", "label":"sample product"}] 

또는 그냥 제공 할 수 있습니다 문자열 배열은 값에 대해 우려하지 않은 경우 :

["product one", "product two"] 

또한 내가 생각대로 자동 완성 제품의 목록을 표시 할 필요가, 당신의 DB를 그냥 ID와 제품 이름을 선택하지 않을 이름?