Click here to Skip to main content
15,867,959 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
i want to populate the datas matching with the ddl_Custid into another ddl ddl_Deviceid

by using JQuery ajax but it's not working where am i doing mistake please point that and how to make it work

Thank You

What I have tried:

                $.ajax({
                    type:   
                    url: '@Url.Action("GetReport", "Report")',
                    dataType: 'json',
                    data: { id: $("ddl_Custid").val() },
                    success: function (datas, status) {
                        var duplicate = [];

                        $("#ddl_Custid").append('<option value="-1">' + "All" + '</option>');

                        $.each(datas, function (i, data) {
                            if (duplicate.indexOf(data.fld_custid) == -1) {
                                $("#ddl_Custid").append('<option value="' + data.fld_custid + '">' + data.fld_custid + '</option>');
                                duplicate.push(data.fld_custid);
                            }

                        });
                    }

                });




$.ajax({
                    type: 'GET',
                    url: '@Url.Action("GetReport", "Report")',
                    dataType: 'json',
                    data: { id: $("#ddl_Deviceid").val() },
                    success: function (datas, status) {
                        var duplicate = [];

                        $("#ddl_Deviceid").append('<option value="-1">' + "All" + '</option>');

                        $.each(datas, function (i, data) {
                            if (duplicate.indexOf(data.fld_deviceid) == -1) {
                                $("#ddl_Deviceid").append('<option value="' + data.fld_deviceid + '">' + data.fld_deviceid + '</option>');
                                duplicate.push(data.fld_deviceid);
                            }

                        });
                    }

                });
Posted
Updated 18-Sep-22 19:50pm

1 solution

I assume you want to display devices for a customer ?
In your example you extend the dropdown $("#ddl_Deviceid") with the selected $("#ddl_Deviceid") value. You may want to fill the devices depending on the value of customer.


$.ajax({
                    type:   
                    url: '@Url.Action("GetReport", "Report")',
                    dataType: 'json',
                    data: { id: $("ddl_Custid").val() },
                    success: function (datas, status) {
                        var duplicate = [];

                        $("#ddl_Deviceid").append('<option value="-1">' + "All" + '</option>');

                        $.each(datas, function (i, data) {
                            if (duplicate.indexOf(data.fld_custid) == -1) {
                                $("#ddl_Deviceid").append('<option value="' + data.fld_custid + '">' + data.fld_custid + '</option>');
                                duplicate.push(data.fld_custid);
                            }

                        });
                    }

                });
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900