请帮帮我 以下是我的源代码。
<script type="text/javascript">
$(document).ready(function () {
SearchText();
SearchccText();
});
function SearchText() {
$(".autosuggest").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "AutoCompleteService.asmx/GetAutoCompleteData",
data: "{'FIRST_NAME':'" + document.getElementById('txtSearch').value + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
}
});
}
function SearchccText() {
$(".autosuggest").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "AutoComplete.asmx/GetAutoCompleteData",
data: "{'EMP_FIRST_NAME':'" + document.getElementById('txtCCSearch').value + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
}
});
}
我的代码在第二个文本框中工作正常,但对于第一个文本框,它不起作用...
请有人帮助我
我的网络服务代码低于......
[WebMethod]
public List<string> GetAutoCompleteData(string FIRST_NAME)
{
List<string> result = new List<string>();
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MySQLConnectionString"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("SELECT EMP_FIRST_NAME + '-' + EMP_CODE AS FIRST_NAME FROM taskcreator_login where FIRST_NAME" +
" LIKE @SearchText", con))
{
con.Open();
cmd.Parameters.AddWithValue("@SearchText", "%" + FIRST_NAME + "%");
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
result.Add(dr["FIRST_NAME"].ToString());
}
return result;
}
}
}
请有人纠正我
答案 0 :(得分:0)
你需要让它们成为单独的类。通过定义$(".autosuggest").autocomplete()
两次,您的第二个定义将覆盖第一个定义。实际上,为此使用ID会更好。您仍然可以保留autosuggest类以用于样式化输入。