jQuery Autocomplete UI从asp页面获取源代码

时间:2013-01-31 14:47:07

标签: jquery-ui jquery asp-classic jquery-autocomplete

如何从经典的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>

2 个答案:

答案 0 :(得分:1)

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

e.g。这就是你的经典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>

答案 1 :(得分:0)

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

在jQuery.com上查看此EXAMPLE

 $( "#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格式返回项目列表。