0

如何从经典的 asp 页面获取 Jquery Autocomplete UI 的源代码?

我找到了默认代码。但我想从另一个asp页面获取我的结果。我如何使用 asp 发送并获取 jQuery?

我需要一点帮助。

<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>jQuery UI Autocomplete - Default functionality</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
  <script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
  <script>
  $(function() {
    var availableTags = [
      "ActionScript",
      "AppleScript",
      "Asp",
      "BASIC",
      "C",
      "C++",
      "Clojure",
      "COBOL",
      "ColdFusion",
      "Erlang",
      "Fortran",
      "Groovy",
      "Haskell",
      "Java",
      "JavaScript",
      "Lisp",
      "Perl",
      "PHP",
      "Python",
      "Ruby",
      "Scala",
      "Scheme"
    ];
    $( "#tags" ).autocomplete({
      source: availableTags
    });
  });
  </script>
</head>
<body>

<div class="ui-widget">
  <label for="tags">Tags: </label>
  <input id="tags" />
</div>


</body>
</html>
4

2 回答 2

1

一种解决方案是响应将数据直接写入输出。

例如,这就是您的经典 asp 的方式:我无法运行此代码,但它应该看起来像这样......

<%
function getListOfTags()
{
  try 
  {
    var objRs = new ActiveXObject("ADODB.Recordset");
  }
  catch (e)
  {
    alert("ADODB namespace not found.");
    exit(0);
  }

  strTagList = "";

  strConn =  "Provider="         +DP+
            ";Initial Catalog="  +DB+
            ";Data Source="      +DS+
            ";Integrated Security=SSPI;"
  strComm = "SELECT ProductID,ProductName,UnitPrice "+
            "FROM Products " + 
            "WHERE CategoryID = 7"  // select Produce

  objRs.open(strComm, strConn, adOpenForwardOnly, adLockReadOnly, adCmdText);

  objRs.MoveFirst();
  while (objRs.EOF != true) 
  {
    strTagList += '"'+objRs("TagName")+'",'
    objRs.MoveNext();
  }
  objRs.Close
  objRs = null;

return (strTagList);
}
%>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>jQuery UI Autocomplete - Default functionality</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
  <script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
  <script>
  $(function() {
    var availableTags = [
      <%= getListOfTags() %>
    ];
    $( "#tags" ).autocomplete({
      source: availableTags
    });
  });
  </script>
</head>
<body>
<div class="ui-widget">
  <label for="tags">Tags: </label>
  <input id="tags" />
</div>  
</body>
</html>
于 2013-01-31T14:51:55.580 回答
0

您可以使用远程数据源进行 jQuery 自动完成。

在 jQuery.com 上查看这个示例

 $( "#birds" ).autocomplete({
   source: "search.asp",
   minLength: 2,
   select: function( event, ui ) {
      log( ui.item ?
      "Selected: " + ui.item.value + " aka " + ui.item.id :
      "Nothing selected, input was " + this.value );
   }
});

search.asp是一个以 JSON 格式返回项目列表的页面。

于 2013-01-31T14:53:36.967 回答