weixin_33671935 2014-10-04 08:15 采纳率: 0%
浏览 14

经典ASP自动完成

I'm using classic ASP to create an auto-complete page. I have two different pages, autocomplete.asp and source.asp. My code as below:

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>

The source.asp return me like this:

[{"ProductId":"111 "}]

Please help

  • 写回答

2条回答 默认 最新

  • weixin_33717117 2014-10-04 14:46
    关注

    I'm not 100% clear on the issue here, but the jquery ui control needs to have data in an expected form of value and label:

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

    Or you can just supply an array of strings if you're not concerned about the values:

    ["product one", "product two"]
    

    You're also not selecting the product name from your db, just the Id, as I assume your autocomplete needs to show a list of product names?

    评论

报告相同问题?

悬赏问题

  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决