jquery を使用してオートコンプリートでいくつかの都市を表示しようとしています。都市を選択すると、目的地 ID が hidden フィールドに設定されます。私は ajax 呼び出しのデータを取得するために Web サービスを使用しています。
これが私のWebサービスメソッドです:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<BALDestinations> AuotExtenderDestination(string destinationname)
{
DataSet ds=objDestination.GetDestination(destinationname);
List<BALDestinations> result = new List<BALDestinations>();
foreach (DataRow dr in ds.Tables[0].Rows)
{
BALDestinations b = new BALDestinations();
b.City = dr["City"].ToString();
b.DestinationId = dr["DestinationId"].ToString();
result.Add(b);
}
return result;
}
これは私のjqueryオートコンプリートテキストボックスエクステンダーのコードです
<script type="text/javascript">
$(document).ready(function () {
SearchText();
$('#btnSearch').click(function () {
alert($("#hiddenAllowSearch").val());
});
});
function SearchText() {
$(".txtdest").autocomplete({
// source: $local_source,
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebService.asmx/AuotExtenderDestination",
data: "{'destinationname':'" + $('.txtdest').val() + "'}",
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (result) {
alert("Error");
}
});
},
focus: function (event, ui) {
$(".txtdest").val(ui.item.label);
return false;
},
select: function (event, ui) {
$(".txtdest").val(ui.item.label);
$("#hiddenAllowSearch").val(ui.item.value);
return false;
}
});
}
</script>
そこに何かを入力すると、未定義がテキストボックスに表示されます