Hi there:
I am trying to use Jquery Autocomplete on Classic ASP populating from a SQL Database.
I am using this page as the Autocomplete Page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
<style>
.ui-autocomplete-loading {
background: white url('http://jqueryui.com/resources/images/ui-anim_basic_16x16.gif') right center no-repeat;
}
</style>
<script>
$(function () {
function log(message) {
$("<div>").text(message).prependTo("#log");
$("#log").scrollTop(0);
}
$("#VendorID").autocomplete({
source: "CustomerJsonAUTO.asp",
minLength: 3,
select: function (event, ui) {
log(ui.item ?
"Selected: " + ui.item.value + " aka " + ui.item.id :
"Nothing selected, input was " + this.value);
}
});
});
function VendorID_onclick() {
}
</script>
</head>
<body>
<div class="ui-widget">
<label for="VendorID">VENDOR: </label>
<input id="VendorID" onclick="return VendorID_onclick()">
</div>
<div class="ui-widget" style="margin-top:2em; font-family:Arial">
Result:
<div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div>
</div>
</body>
</html>
AND THIS PAGE AS THE HELPER Or Search Page:
<% @LANGUAGE="VBSCRIPT" CODEPAGE="65001" %>
<!--#include file="JSON_2.0.4.asp"-->
<%
Function QueryToJSON(dbcomm, params)
Dim rs, jsa
Set rs = dbcomm.Execute()
Set jsa = jsArray()
Do While Not (rs.EOF Or rs.BOF)
Set jsa(Null) = jsObject()
For Each col In rs.Fields
jsa(Null)(col.Name) = col.Value
Next
rs.MoveNext
Loop
Set QueryToJSON = jsa
rs.Close
End Function
%>
<%
strConn = "Connection String"
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open strConn
query ="Select [vendor_num],[PAYEE] from [TABLE] where [PAYEE] = 'attorney'"
vendor_num = Request.QueryString("vendor_num")
arParams = array(vendor_num)
Set cmd = Server.CreateObject("ADODB.Command")
cmd.CommandText = query
Set cmd.ActiveConnection = conn
QueryToJSON(cmd, arParams).Flush
conn.Close : Set Conn = Nothing
%>
The helper or search page outputs JSON:
[{"vendor_num":"991085","P1":"ATTORNEY A"},{"vendor_num":"799","P2":"ATTORNEY G"}]
I did check and I believe the Json is valid. I think that I need to convert the json to ajax or change the values to value and id. But I am kind of stuck right now as which way to go.
Any help would be greatly appreciated!
Thanks in advance! Brett