自动完成HTML中的错误404(使用ASP.NET和JQuery) [英] Auto complete ERROR 404 in HTML (using ASP.NET and JQuery)
问题描述
由于asp.net项目中的某些原因,我的自动完成功能无法正常工作,我尝试了多种方法,除了在数据连接中使用数据源外,其他方法均无济于事.我已经为其创建了一个名为Diagnose的数据库,但是由于某种原因,它在jquery上显示错误404.
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. I have already created a database for it called Diagnose but for some reason, it displays error 404 on jquery.
这是我的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>
这是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;
}
它显示错误:
当我打开jquery-1.8.0.js:8214
时,向我显示此xhr.send( ( s.hasContent && s.data ) || null );
When I open the jquery-1.8.0.js:8214
it shows me this xhr.send( ( s.hasContent && s.data ) || null );
我在这个问题上停留了一段时间,所以任何帮助都会很大,在此先感谢:D< 3
I'm stuck at this problem for a while so any help would be great, thanks in advance :D <3
推荐答案
它返回404找不到.我认为GetSearch应该在aspx或ascx文件中. Webmethod可在System.Web上下文中使用,并且在某些情况下将需要Page.
It is returning 404 not found. I think that GetSearch should be inside of an aspx or an ascx file. Webmethod works in System.Web context and in some point it will require Page.
这篇关于自动完成HTML中的错误404(使用ASP.NET和JQuery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!