i have auto complete text box
this is the script
- <head>
- <script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
- <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
- <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
- </head>
- <body>
- <input id='CountryName'/>
- <span id='CountryID'></span>
- var data2;
- $.ajax({
- url: '/Home/GetRecord',
- dataType: "json",
- data: data2,
- success: function (data) {
- data2 = data;
- },
- error: function (xhr, status, error) {
- alert("Error");
- }
- });
- $('#CountryName').autocomplete({
- data: { search: $("#searchInput").val() },
- source: function y(request, response) {
- response($.map(data2, function (item) {
- return {
- label: item.t,
- value: item.t
- }
- }));
- }
- ,
- select: function (e, ui) {
- e.preventDefault();
- $(this).val(ui.item.label);
- $('#CountryID').html(ui.item.value);
- }
- });
- </script>
this is the controller
- [HttpGet]
- public JsonResult GetRecord(string prefix)
- {
- DataSet dst = new DataSet();
- dst.Tables.Add(op.GetName(prefix));
- List<DataSearch> searchlist = new List<DataSearch>();
- foreach (DataRow dr in dst.Tables[0].Rows)
- {
- searchlist.Add(new DataSearch
- {
- t = dr["ARTICAL_NAME"].ToString()
- });
- }
- return Json(searchlist , JsonRequestBehavior.AllowGet);
- }
when i click in text box that ajax call not work , i call it from url like this https://localhost:44330/home/GetRecord?prefix=t
and the result
[{"t":"test"},{"t":"test from it "},{"t":"table "}] and appear in new page
any help to make result appear as dropdown when i start write inside textbox