【发布时间】:2014-05-14 13:11:09
【问题描述】:
请帮帮我 下面是我的源代码。
<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;
}
}
}
请大神指正
【问题讨论】:
-
这应该是 data: "{'FIRST_NAME':'" 而不是 data: "{'EMP_FIRST_NAME':'"
-
嗨,我按照你所说的尝试过,但仍然无法正常工作。它没有被过滤
-
两者都有 $(".autosuggest").autocomplete({}) 。您对“.autsuggest”类有多少控件?总是第二个会覆盖第一个
-
您好,还需要一个建议。我最初想加载前 10 个结果,然后再次加载
-
@user3331850 scottsjewels.blogspot.com/2013/06/…
标签: c# jquery web-services