0

I am using autocomplete for the Location names as shown

$(document).ready(function () {
       debugger;
       $('#txtLocationName').autocomplete({

           source: 'LocationHandler.ashx?type='+ $("#<%= ddlDivision1.ClientID %> option:selected").val()
          ///LocationHandler.ashx?term=p

        });
    });

The Autocomplete should show the name base on what division is selected in Drop Down.

  <td class="auto-style48">
                <asp:DropDownList ID="ddlDivision1" CssClass="form-input-field" runat="server"  ></asp:DropDownList>

            </td>
             <td class="auto-style48">
                <asp:TextBox ID="txtLocationName" runat="server" Width="350px" CssClass="textboxAuto"  Font-Size="12px" />
            </td>

And in Handler i do have logic for divisiontype .

 public class LocationHandler : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        string term = context.Request["term"] ?? "";
        string type = context.Request["type"] ?? "";

and in the type i am only getting "-1" and not selected value. not sure why ? please advice !!

Please advice !!

  • After `source: 'LocationHandler.ashx?type=...'` make a `console.log($("#<%= ddlDivision1.ClientID %> option:selected").val())` to verify if you are actually getting the desired value. To view the log (if you're in Chrome) head to Tools >> Developer tools. – Máster Oct 04 '18 at 22:21
  • I am actually not getting anything. its always '-1'. – user7776356 Oct 04 '18 at 23:05

1 Answers1

0

I fixed as passing as a query string in request.

<script>
    $(document).ready(function () {
        src = 'LocationHandler.ashx';
        debugger;
        $('#txtLocationName').autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: src,
                    dataType: "json",
                    data: {
                        term: request.term,
                        type: $("#ddlDivision1").val()
                    },
                    success: function (data) {
                        response(data);
                    }
                });
            },
            min_length: 3,
            delay: 300
        });
    });

</script>