我通过ajax获取数据并在文本框中显示但是在插入逗号并开始搜索其他文本后它没有显示建议。
这是我的测试框。
<asp:Label ID="lblEmployee" Text="Employee Search" runat="server"></asp:Label>
<asp:TextBox ID="txtEmployee" runat="server" Width="200" placeholder="Employee Name"></asp:TextBox>
这是我的ajax功能
<script type="text/javascript">
$(document).ready(function () {
$("#txtEmployee").autocomplete({
source: function (request, response) {
var param = { EmpName: $('#txtEmployee').val() };
$.ajax({
url: "ChangeRequestForm.aspx/getEmployees",
data: JSON.stringify(param),
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
dataFilter: function (data) { return data; },
success: function (data) {
console.log(JSON.stringify(data));
response($.map(data.d, function (item) {
return {
value: item.EmpName + " (" + item.Address + ")"
}
}))
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
var err = eval("(" + XMLHttpRequest.responseText + ")");
alert(err.Message)
// console.log("Ajax Error!");
}
});
},
minLength: 1
});
});
</script>
这是我的功能背后的代码
[WebMethod]
public static List<MonitoringDataFormBE> getEmployees(string EmpName)
{
List<MonitoringDataFormBE> empObj = new List<MonitoringDataFormBE>();
//string cs = ConfigurationManager.ConnectionStrings["conStr"].ToString();
try
{
using (OracleConnection con = new OracleConnection(ConStringforPhase))
{
using (OracleCommand com = new OracleCommand())
{
com.CommandText = string.Format("select school_code from change_log where school_code like '{0}%'", EmpName);
com.Connection = con;
con.Open();
OracleDataReader sdr = com.ExecuteReader();
MonitoringDataFormBE emp = null;
while (sdr.Read())
{
emp = new MonitoringDataFormBE();
emp.SCHOOL_CODE = Convert.ToString(sdr["SCHOOL_CODE"]);
empObj.Add(emp);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error {0}", ex.Message);
}
return empObj;
}
目前代码只返回一个单词的建议,而不是在逗号后面的文字框中,当我尝试在逗号后面的文本框中输入任何内容