[英]Auto complete ERROR 404 in HTML (using ASP.NET and JQuery)
For some reason in asp.net project, my autocomplete won't work, I have tried different methods from using Data source in data connection but to no avail.出于某种原因,在 asp.net 项目中,我的自动完成不起作用,我尝试了在数据连接中使用数据源的不同方法,但无济于事。 I have already created a database for it called Diagnose but for some reason, it displays error 404 on jquery.
我已经为它创建了一个名为 Diagnose 的数据库,但由于某种原因,它在 jquery 上显示错误 404。
Here is my HTML code:这是我的 HTML 代码:
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.0.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/jquery-ui.js"></script>
<script>
$(function () {
$("#search-diagnosis").autocomplete({
source: function (request, response) {
var param = {
searchdetails: $('#search-diagnosis').val()
};
$.ajax({
url: "SearchController.cs/GetSearch",
data: JSON.stringify(param),
type: "post",
contentType: "application/json; charset=utf-8",
dataFilter: function (data) { return data; },
success: function (data) {
response($.map(data.d, function (item) { return { value: item } }))
},
});
},
minLength: 1
});
});
</script>
<div class="search">
<input id="search-diagnosis" class="w-75" type="text" placeholder="Start typing your diagnois...">
</div>
Here is CS code:这是CS代码:
[WebMethod]
public static List<string> GetSearch(string searchdetails)
{
List<string> search = new List<string>();
string mainconn = ConfigurationManager.ConnectionStrings["mybase.database"].ConnectionString;
SqlConnection sqlconn = new SqlConnection(mainconn);
string sqlquery = string.Format("select Name from [dbo].[Diagnose] where Name LIKE '%{0}%'", searchdetails);
sqlconn.Open();
SqlCommand sqlcomm = new SqlCommand(sqlquery, sqlconn);
SqlDataReader sdr = sqlcomm.ExecuteReader();
while (sdr.Read())
{
search.Add(sdr.GetString(0));
}
sqlconn.Close();
return search;
}
It displays error:它显示错误:
When I open the
jquery-1.8.0.js:8214
it shows me this xhr.send( ( s.hasContent && s.data ) || null );
当我打开
jquery-1.8.0.js:8214
它向我显示了这个xhr.send( ( s.hasContent && s.data ) || null );
I'm stuck at this problem for a while so any help would be great, thanks in advance :D <3我被这个问题困住了一段时间,所以任何帮助都会很棒,在此先感谢:D <3
It is returning 404 not found.它返回 404 not found。 I think that GetSearch should be inside of an aspx or an ascx file.
我认为 GetSearch 应该在 aspx 或 ascx 文件中。 Webmethod works in System.Web context and in some point it will require Page.
Webmethod 在 System.Web 上下文中工作,在某些时候它需要 Page。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.