Jquery 我得到TypeError:$(…)。自动完成并非始终是一个函数
我对ASP.NETMVC中的jquery和ajax一无所知。我想我的一个文本字段将自动完成。目前这是我的实现,但出于某种原因,我出现了以下错误:Jquery 我得到TypeError:$(…)。自动完成并非始终是一个函数,jquery,asp.net-mvc,Jquery,Asp.net Mvc,我对ASP.NETMVC中的jquery和ajax一无所知。我想我的一个文本字段将自动完成。目前这是我的实现,但出于某种原因,我出现了以下错误: TypeError: $(...).autocomplete is not a function 当我进去时,我得到: <anonymous> Create:36 jQuery.Callbacks/fire() jquery-1.10.2.js:3048 jQuery.Callbacks/self.fireWith() jquer
TypeError: $(...).autocomplete is not a function
当我进去时,我得到:
<anonymous>
Create:36
jQuery.Callbacks/fire()
jquery-1.10.2.js:3048
jQuery.Callbacks/self.fireWith()
jquery-1.10.2.js:3160
.ready()
jquery-1.10.2.js:433
completed()
jquery-1.10.2.js:104
这是我的视图文件create.cshtml:
@model StudentsManagment.Models.student
<link href="~/Content/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" />
<script src="~/scripts/jquery-1.10.2.js"></script>
<script src="~/scripts/jquery-ui-1.10.4.custom.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#citySearch").autocomplete({
source: function(request,response) {
$.ajax({
url: "/Home/AutoCompleteCountry",
type: "POST",
dataType: "json",
data: { term: request.term },
success: function (data) {
response($.map(data, function (item) {
return { label: item.Country, value: item.Country };
}))
}
})
},
messages: {
noResults: "", results: ""
}
});
})
</script>
@{
ViewBag.Title = "Create";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Create</h2>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Student</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.First_name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.First_name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.First_name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Last_name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Last_name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Last_name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Date_of_birth, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Date_of_birth, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Date_of_birth, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Student_id, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Student_id, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Student_id, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.City, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBox("searchCity", null, new { @class = "form-control", id = "citySearch" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Description, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Description, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Description, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
是jquery错误还是我的cshtml文件有问题?请检查布局文件是否没有jquery或jquery UI。如果它这样做,那么由于重复的文件,它可能会导致问题
另外,我建议您将所有脚本文件和javascript代码移到页面底部,而不是页面顶部。您使用了query-ui-1.10.4.custom.min,那么您的自定义jqui文件是否有自动完成方法?而且您面对的是TypeError,所以您可能传递了错误的数据类型值您是什么意思自定义jqui文件我应该像这样构建一个?当页面加载时,我没有传递任何信息,我单击F12,我看到了这种错误。你能为此创建JSFIDLE吗?我不喜欢,我只是想看一个例子,如何在asp.NET中使用jquery的自动完成方法。我在布局中没有其他文件,但我在脚本文件夹中有其他js文件。这有什么关系吗?没有没关系。能否检查jquery UI文件是否正确加载。另外,您还没有在此处发布布局文件,因此我无法看到。布局文件是cshtm文件!我发现这一行有错误:$citySearch.autocomplete