1
請幫助我 以下是我的源代碼。我的自動完成不適用於同一頁中的兩個字段
<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");
}
});
}
});
}
我的代碼是在第二個文本框工作正常,但第一個它不工作... 請人幫我 我的Web服務代碼如下...
[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;
}
}
}
請有人糾正我
這應該是數據:「{'FIRST_NAME':'」而不是數據:「{'EMP_FIRST_NAME':'」 –
嗨我試着按你說的,但它仍然無法正常工作。它沒有得到過濾 – user3331850
都有$(「。autosuggest」)。autocomplete({})。您有多少類控件「.autsuggest」?總是第二個會覆蓋第一個 – malkam