TransWikia.com

Auto complete ERROR 404 in HTML (using ASP.NET and JQuery)

Stack Overflow Asked on December 31, 2020

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.

Here is my HTML code:

<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:

[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:

This error
When I open the jquery-1.8.0.js:8214 it shows me this 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 😀 <3

One Answer

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.

Answered by Kev on December 31, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP