Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.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 获取下拉列表,具体取决于响应_Javascript_Jquery_Asp.net Mvc - Fatal编程技术网

Javascript 获取下拉列表,具体取决于响应

Javascript 获取下拉列表,具体取决于响应,javascript,jquery,asp.net-mvc,Javascript,Jquery,Asp.net Mvc,我有3个单选按钮,如: <input type="radio" name="editList" value="Proveedor">Proveedor <input type="radio" name="editList" value="Usuario">Usuario <input type="radio" name="editList" value="Sucursal">Sucursal 如果选择Sucursal,则加载这部分js $.getJSO

我有3个单选按钮,如:

 <input type="radio" name="editList" value="Proveedor">Proveedor
 <input type="radio" name="editList" value="Usuario">Usuario
 <input type="radio" name="editList" value="Sucursal">Sucursal
如果选择Sucursal,则加载这部分js

$.getJSON("@Url.Action("GetSucursal", "Agenda")", function (data) {

                $.each(data, function (index, item) {
                    items += "<option value='" + item.ID + "'>" + item.Sucursal+ "</option>";
                });
                $("#lstProveedor").html(items);
$.getJSON(@Url.Action(“GetSucursal”,“Agenda”)”),函数(数据){
$。每个(数据、功能(索引、项目){
items+=''+item.Sucursal+'';
});
$(“#lstProveedor”).html(项目);
我怎样才能做到这一点

更新:

<script type="text/javascript">
    $(function () {
        var items = "";
        $.getJSON("@Url.Action("GetProveedores", "Agenda")", function (data) {

            $.each(data, function (index, item) {
                items += "<option value='" + item.ID + "'>" + item.NombreComercial + "</option>";
            });
            $("#lstProveedor").html(items);
        });

    });
</script>
作为拉蒙的回答,我确实:

<script type="text/javascript">
    $(function getJsonProveedores() {
        var items = "";
        $.getJSON("@Url.Action("GetProveedores", "Agenda")", function (data) {

            $.each(data, function (index, item) {
                items += "<option value='" + item.ID + "'>" + item.NombreComercial + "</option>";
            });
            $("#lstProveedor").html(items);
        });

    });
    $(function getJsonUnidades() {
        var items = "";
        $.getJSON("@Url.Action("GetUnidades", "Agenda")", function (data) {

            $.each(data, function (index, item) {
                items += "<option value='" + item.ID + "'>" + item.Nombre + "</option>";
            });
            $("#lstProveedor").html(items);
        });


    });
    $(function getJsonUsuarios() {
        var items = "";
        $.getJSON("@Url.Action("GetUsuario", "Agenda")", function (data) {

            $.each(data, function (index, item) {
                items += "<option value='" + item.ID + "'>" + item.Nombre + "</option>";
            });
            $("#lstProveedor").html(items);
        });

        $('input[type=radio][name=editList]').change(function () {
            if (this.value == 'Proveedor') {
                getJsonProveedores();
            }
            else if (this.value == 'Sucursal') {
                getJsonUnidades();
            }
            else if (this.value == 'Usuario') {
                getJsonUsuarios();
            }
        });

    });
</script>

$(函数getJsonProveedores(){
var项目=”;
$.getJSON(@Url.Action(“GetProveeStores”、“Agenda”)”),函数(数据){
$。每个(数据、功能(索引、项目){
items+=“”+item.nombrecomeral+“”;
});
$(“#lstProveedor”).html(项目);
});
});
$(函数getJsonUnidades(){
var项目=”;
$.getJSON(@Url.Action(“GetUnidades”、“议程”)”),函数(数据){
$。每个(数据、功能(索引、项目){
items+=“”+item.Nombre+“”;
});
$(“#lstProveedor”).html(项目);
});
});
$(函数getJsonUsuarios(){
var项目=”;
$.getJSON(@Url.Action(“GetUsuario”,“议程”)”),函数(数据){
$。每个(数据、功能(索引、项目){
items+=“”+item.Nombre+“”;
});
$(“#lstProveedor”).html(项目);
});
$('input[type=radio][name=editList]')。更改(函数(){
如果(this.value=='Proveedor'){
getJsonProveedores();
}
else if(this.value==“Sucursal”){
getJsonUnidades();
}
else if(this.value==“Usuario”){
getJsonUsuarios();
}
});
});
但在Chrome控制台中,我发现两个错误:

未捕获引用错误:GetJSonProveeStores未定义为未捕获 ReferenceError:未定义getJsonUnidades


我创建了一个html文件,其工作原理如下:

function getJsonProveedores() {
    var items = "";
    console.log('teste proveedor');

};
function getJsonUnidades() {
    var items = "";
    console.log('unidades');
};
function getJsonUsuarios() {
    console.log('usuarios');
};
$(function() {
  $('input[type=radio][name=editList]').change(function() {
        if (this.value == 'Proveedor') {
            getJsonProveedores();
        } else if (this.value == 'Usuario') {
            getJsonUsuarios();
        } else if (this.value == 'Sucursal') {
            getJsonUnidades();
        }
    });
});

我试着把它作为你的评论,但我发现了问题,我更新了我的问题,你能检查一下吗?你必须实现这个功能,我只是向你展示了让我再帮你一点的方法。我实现了它,它工作了,只为一个问题。当我选择一个时,它正确加载,但如果我选择第二个,它也正确运行,问题是我仍然得到了解决第一个单选按钮的值。选择第二个单选按钮后如何将其删除?
<script type="text/javascript">
    $(function getJsonProveedores() {
        var items = "";
        $.getJSON("@Url.Action("GetProveedores", "Agenda")", function (data) {

            $.each(data, function (index, item) {
                items += "<option value='" + item.ID + "'>" + item.NombreComercial + "</option>";
            });
            $("#lstProveedor").html(items);
        });

    });
    $(function getJsonUnidades() {
        var items = "";
        $.getJSON("@Url.Action("GetUnidades", "Agenda")", function (data) {

            $.each(data, function (index, item) {
                items += "<option value='" + item.ID + "'>" + item.Nombre + "</option>";
            });
            $("#lstProveedor").html(items);
        });


    });
    $(function getJsonUsuarios() {
        var items = "";
        $.getJSON("@Url.Action("GetUsuario", "Agenda")", function (data) {

            $.each(data, function (index, item) {
                items += "<option value='" + item.ID + "'>" + item.Nombre + "</option>";
            });
            $("#lstProveedor").html(items);
        });

        $('input[type=radio][name=editList]').change(function () {
            if (this.value == 'Proveedor') {
                getJsonProveedores();
            }
            else if (this.value == 'Sucursal') {
                getJsonUnidades();
            }
            else if (this.value == 'Usuario') {
                getJsonUsuarios();
            }
        });

    });
</script>
function getJsonProveedores() {
    var items = "";
    console.log('teste proveedor');

};
function getJsonUnidades() {
    var items = "";
    console.log('unidades');
};
function getJsonUsuarios() {
    console.log('usuarios');
};
$(function() {
  $('input[type=radio][name=editList]').change(function() {
        if (this.value == 'Proveedor') {
            getJsonProveedores();
        } else if (this.value == 'Usuario') {
            getJsonUsuarios();
        } else if (this.value == 'Sucursal') {
            getJsonUnidades();
        }
    });
});