如何通过Javascript将Dropdownlist索引作为参数发送到WS?

如何通过Javascript将Dropdownlist索引作为参数发送到WS?,javascript,c#,jquery,asp.net,web-services,Javascript,C#,Jquery,Asp.net,Web Services,我正在尝试使用Jquery自动完成功能向我的WS发送2个参数: 文本框,我想要完成的地方 下拉列表索引 我在获取dropdownlist索引时遇到问题,因为我只获取控制器的名称 这是我的剧本: <script type="text/javascript" language="javascript"> $(function() { $('#<%= TextBoxes1.ClientID%>').autocomplete({ s

我正在尝试使用Jquery自动完成功能向我的WS发送2个参数:

文本框,我想要完成的地方 下拉列表索引 我在获取dropdownlist索引时遇到问题,因为我只获取控制器的名称

这是我的剧本:

<script type="text/javascript" language="javascript">
    $(function() {
        $('#<%= TextBoxes1.ClientID%>').autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: "WB/EmployeeService.asmx/GetEmpolyeeId",
                    data: "{ 'Text': '" + request.term + "','SelectedIndex':'" + '#<%= DP1.ClientID %>' + "'}",
                    type: "POST",
                    dataType: "json",
                    contentType: "application/json;charset=utf-8",
                    success: function (result) {
                        response(result.d);

                    },
                    error: function (response) {
                        alert(response.responseText);
                    },
                    failure: function (response) {
                        alert(response.responseText);
                    }
                });
            },
            minLength: 0
        });

    });

</script>
这是我的WS:

public List<string> GetEmpolyeeId(string Text, string SelectedIndex)

我需要做些什么才能使它工作?

正如您在问题中提到的,您需要以下2项

textbox,在这里我想要complete-request.term,您使用它是正确的。 dropdownlist index-假设dropdownlist id是DP1,您需要使用以下命令获取其索引 $[0]。已选择索引

所以把所有的东西放在一条线上

数据:{'Text':'+request.term+','SelectedIndex':'+$[0]。SelectedIndex+'}

范例

函数OnChangeVal{ 警报$sel[0]。已选择索引; } 沃尔沃汽车 萨博 梅赛德斯 奥迪 我明白了!!!:-

这就是我所做的:

<script type="text/javascript" language="javascript">
    var ddl = document.getElementById('<%=DP1.ClientID%>');
    $(function () {
        $('#<%= TextBoxes1.ClientID%>').autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: "WB/EmployeeService.asmx/GetEmployeeDetails",
                    data: "{ 'Text': '" + request.term + "','SelectedIndex':'" + ddl.selectedIndex  <%--'#<%= DP1.ClientID %>'--%> + "'}",
                    type: "POST",
                    dataType: "json",
                    contentType: "application/json;charset=utf-8",
                    success: function (result) {
                        response(result.d);
                    },
                    error: function (response) {
                        alert(response.responseText);
                    },
                    failure: function (response) {
                        alert(response.responseText);
                    }
                });
            },
            minLength: 0
        });

    });
</script>
我在Dropdownlist索引中添加了一个变量,同时在进入函数之前定义了Dropdownlist


WS的样式相同。

我不能在答案上加V,因为我没有权限。如果有人愿意,我会很感激的。非常感谢。