2

我有一个 DropDownList,其中包含从 SQL Server 数据库填充的文本字段和值字段。我希望得到用户选择的值字段并输入到 JavaScript 中“术语:请求术语”下方的“国家:”。感谢这里的每一位成员的帮助。

下拉列表:

<asp:DropDownList ID="CountryDDL" runat="server" Height="100%"></asp:DropDownList>

JavaScript:

<script>
    $(function () {
        $("[id$=OriginLocationTextBox]").autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: "https://api.sandbox.amadeus.com/v1.2/airports/autocomplete",
                    dataType: "json",
                    data: {
                        apikey: "API KEY",
                        term: request.term,
                        country: 
                    },
                    success: function (data) {
                        response(data);
                    }
                });
            },
            minLength: 3,
        });
    });
</script>
4

1 回答 1

2

如果你不需要通过 .net 但 ajax 收集数据,你可以这样做:

下拉列表:

<asp:DropDownList ID="CountryDDL" runat="server" Height="100%" onchange="requestfunc(this.options[this.selectedIndex].value)"></asp:DropDownList>

JavaScript:

<script>
    function requestfunc(val){
    $(function () {
        $("[id$=OriginLocationTextBox]").autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: "https://api.sandbox.amadeus.com/v1.2/airports/autocomplete",
                    dataType: "json",
                    data: {
                        apikey: "API KEY",
                        term: request.term,
                        country: val
                    },
                    success: function (data) {
                        response(data);
                    }
                });
            },
            minLength: 3,
        });
    });
    }
</script>
于 2018-04-27T04:17:39.927 回答