我已经按照以下格式实现了 JQuery 自动完成功能: AddApplication.cshtml
@page
@model AddApplicationModel
@{
}
<div>
<form>
<div>
<input type="text" name="appName" placeholder="Enter Application Name">
<select asp-items="Model.ministryItems">
<option>Select Ministry</option>
</select>
</div>
<div>
<input type="text" name="url" id="url" placeholder="Search for a URL" autocomplete="on">
</div>
</form>
</div>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/start/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script type="text/javascript">
$(function () {
$("#url").autocomplete({
source: function (request, response) {
console.log("in funct");
$.ajax({
url: "@Url.Action("GetURL","AddApplication")",
data: ({ term: request.term}),
dataType: "json",
type: "GET",
contentType: "application/json; charset=utf-8",
success: function (data) {
Console.log("success");
response($.map(data, function (item) {
Console.log("response"+item)
return item;
}))
}
});
},
select: function (e, i) {
$("#url").val(i.item.val);
},
minLength: 0
}).focus(function () {
$(this).autocomplete("search");
});
});
</script>
当我在文本框中输入内容时,什么也没有发生。经过一些调试后,我知道函数$("url").autocomplete正在被调用,但success: function()data{}没有被击中
HUWWW
呼啦一阵风
相关分类