jQuery Ajax population of dropdowns

jQuery Ajax population of dropdowns

本文关键字:dropdowns of population Ajax jQuery      更新时间:2023-09-26

我对 ajax 的 3 个下拉列表的动态种群有问题

  $.ajax({
            url:"loadPersons",
            success:function(data) {
                loadPersons(data);
            },
            error: function (xhr, ajaxOptions, thrownError) {
            }
        });

这是我的另一个阿贾克斯

 $.ajax({
                    url:"loadCars?personId=8796093056989",
                    data:{"personId":personId},
                    success:function(data) {
                        loadCars(data);
                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                    }

第一个返回所有人,第二个应返回具有指定ID的人的汽车。但是,当我按下第一个下拉菜单中的某些内容时,所有对象都会进入第二个下拉列表。您知道如何进行过滤吗?

你不应该使用类似的东西吗

url:"loadCars?personId="+$('#persons-ddl').val()

将第二个 ajax 调用更改为:

$.ajax(
{
    url:"loadCars",
    data:
    {
        "personId":personId // this is the id of the selected person in your person combobox
    },       
    error: function (xhr, ajaxOptions, thrownError) 
    {
    }
}).done(function(data)
{
   loadCars(data);
});