Click here to Skip to main content
15,440,964 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have applied this upon an input type text, but it is not working. I need some guidance to show me where I am going wrong. This is javascript code and is not working:
JavaScript
$(document).ready(function () {
    $('#reasondescriptiontxtbox').autocomplete( {
        source: function (request, response) {
            $.ajax( {
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "Default.aspx/getReason",
                data: "{'keywords':'" + request.term + "'}",
                dataType: "json",
                async: true,
                success: function (data) {
                    response(data.d);
                },
                error: function (result) {
                    //alert("Error");
                }
            });
        },
        minLength: 2
    });
});

code behind:
C#
[WebMethod]
public static IList<string> getReason(string keywords)
{
    int count = 0;
    IList<string> result = new List<string>();
    string constr 
        = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
    SqlConnection con1 = new SqlConnection(constr);
    SqlCommand cmd1 = con1.CreateCommand();
    cmd1.CommandText = "select distinct Code_Description from CODE_DESCRIPTION_277 where Code_Description '%" + keywords + "%'";

    try
    {
        con1.Open();
        SqlDataReader dr = cmd1.ExecuteReader();

        while (dr.Read())
        {
            count++;
            result.Add(dr["Code_Description"].ToString());

            if (count == 100)
                break;
        }

        con1.Close();

        return result;
    }
    catch
    {
        return null;
    }
}

Will I have to add some sort of jQuery file?
Posted
Comments
Madhav Hatwalne 16-May-13 4:20am    
Have you added jQuery and jQuery UI files????
Qadri Jillani 16-May-13 6:07am     CRLF
no if you know which file should be added so kindly let me know.thanx in advance

1 solution

source: is a function and the return type of it must be an array, so you can try this:
C#
success: function (data) {
    return data;
},
error: function (result) {
    return [];
}

If it does not work, you can try to change
IList<string>
to
List<string>
instead.
Hope this help.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900