这是代码:
$("#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 成功功能上放置的正确代码是什么