這是代碼:TAG-IT和自動完成功能
$("#AddFriendToGroup").tagit({
autocomplete: {
source: function (request, response) {
$.ajax({
type: 'POST',
url: 'ChatPageTest.aspx/tagFriendAutocomplete',
data: "{'ClientID':'" + $("#UserID").val() + "','ClientName': '" + request.term + "'}",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (data) {
},
error: function (xhr) {
alert("responseText: " + xhr.responseText);
}
});
},
minLength: 2
}
});
服務器端:
public static string tagFriendAutocomplete(int ClientID,string ClientName)
{
string Result = "";
string query = "select fr.FRIEND_ID,c.[USER_NAME] from clients c inner join friends fr on c.CLIENT_ID=fr.FRIEND_ID and fr.CLIENT_ID=" + ClientID + " and c.[USER_NAME] like '%" + ClientName + "%' ";
DataTable dt = new SQLHelper(SQLHelper.ConnectionStrings.WebSiteConnectionString).getQueryResult(query);
if (dt.Rows.Count > 0)
{
for(int i=0;i<dt.Rows.Count;i++)
{
Result += dt.Rows[i]["FRIEND_ID"] + "," + dt.Rows[i]["USER_NAME"];
}
}
return Result;
}
我很困惑,我不知道什麼是正確的代碼把Ajax的成功函數任何人都可以幫助我如何在我的情況下使tagit工作的自動完成功能顯示由ajax調用產生的clientName
這是一個很好的答案,但我有一個簡單的問題也是responce包含一個標籤和值希望應該是客戶端的ID如果我們說我想將這些ID存儲在一個隱藏的領域我該如何實現這一目標? – Sora