Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在jquery中从webservice获取数据?_Javascript_Jquery_Asp.net Mvc_Web Services - Fatal编程技术网

Javascript 如何在jquery中从webservice获取数据?

Javascript 如何在jquery中从webservice获取数据?,javascript,jquery,asp.net-mvc,web-services,Javascript,Jquery,Asp.net Mvc,Web Services,我有一个带有链接的web服务:http://41.128.183.109:9090/api/data/getalllocations 我使用jquery在下拉列表中接收到该数据。该数据包含两个对象LocationName和LocID。我想在jQuery的下拉更改函数中显示一个带有LocID的警报。这是我的密码: $(document).ready(function () { $.ajax({ type: 'Get', url: 'http://41.128

我有一个带有链接的web服务:http://41.128.183.109:9090/api/data/getalllocations

我使用jquery在下拉列表中接收到该数据。该数据包含两个对象LocationName和LocID。我想在jQuery的下拉更改函数中显示一个带有LocID的警报。这是我的密码:

$(document).ready(function () {
    $.ajax({
        type: 'Get',
        url: 'http://41.128.183.109:9090/api/data/getalllocations',
        success: function (data) {
            var SubDropdown = $("#main");
            for (var i = 0; i < data.length; i++) {
                SubDropdown.append('<option value?' + i + '?="">' + data[i].LocationName + '</option>');
            }
        }
    });
});

$("#countries").change(function () {
    alert();
});
以下是我的HTML代码:

<select tabindex="-1" class="select2_group form-control" style="display: normal; width: 290px;" name="countries" id="countries">
    <optgroup label="Select Your City" id="main"></optgroup>
</select> 
请尝试以下内容

 $(document).ready(function () {
    $.ajax({
        type: 'Get',
        url: 'http://41.128.183.109:9090/api/data/getalllocations',
        success: function (data) {
            var SubDropdown = $("#main");
            for (var i = 0; i < data.length; i++) {
                SubDropdown.append('<option value="' + data[i].LocID + '">' + data[i].LocationName + '</option>');
            }
        }
    });

    $("#countries").change(function () {
        alert($("#countries").val());
    });
});

你需要更好地描述问题所在。奇怪。。。现在和我的答案完全一样,但我投了反对票。。。HmmmmI希望在下拉列表中显示位置名称。但当我发出警报时,我想显示LocID。我可以这样做吗。