我正在使用asp并从其他文件中获取数据以进行自动完成。我尝试了很多方法,但我没有得到选择记录的id值。
$().ready(function() {
function formatItem(row) {
return row[0] + " (<strong>id: " + row[1] + "</strong>)";
}
function formatResult(row) {
return row[0].replace(/(<.+?>)/gi, '');
}
$("#Datt").autocomplete("get_data.asp", {
width: 600,
selectFirst: true,
scroll:false,
max: 25,
select: function( event, ui ) {}
});
$("#Datt").result(function(event, data, formatted) {
if (data)
$(this).parent().next().find("Datt").val(data[1]);
window.scrollTo(0,1)
setTimeout(function() {
$("#OtherDatt").focus();
});
});
});
以下get_data.asp代码......
<%
qq = (Request.QueryString("q"))
set rsUrun=Server.CreateObject("ADODB.recordset")
rsUrun.Open "Select * from tbl_Customers WHERE Name like '%" & qq & "%' ORDER BY Name ASC", bag,1,3
If rsUrun.RecordCount > 0 Then
i = 1
Sinirla = 10
Do While Not rsUrun.EOF And i < (Sinirla + 1) %>
<%=rsUrun("Adi")%> <%= vbCrlf %>
<%
i = i + 1
rsUrun.MoveNext
Loop
End If
%>
感谢您的帮助...
答案 0 :(得分:0)
我在asp文件中解决了我的问题。 get_data.asp代码如下。
If rsUrun.RecordCount > 0 Then
i = 1
Sinirla = 10
output = "["
Do While Not rsUrun.EOF And i < (Sinirla + 1)
output = output & "{""id"":""" & rsUrun("ID") & """,""value"":""" & rsUrun("Adi") & """},"
i = i + 1
rsUrun.MoveNext
Loop
output=Left(output,Len(output)-1)
output = output & "]"
End If
Response.Write output