2014-10-04 152 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 "}]

請幫助

+0

您的第二段代碼似乎沒有正確格式化;你似乎缺少'document','html'和'head'標籤(儘管這與你所遇到的沒有多大關係)。 – Paul 2014-10-06 12:53:19

回答

-1

我不是這裏的問題100%清楚,但jQuery UI的控制需要具有的價值和標籤預期表單數據:

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

或者你也可以提供字符串數組,如果你不關心的值:

["product one", "product two"] 

你還沒有從你的數據庫,只是標識選擇產品名稱,因爲我認爲你自動完成需要展示產品列表名字呢?