dougu4704 2015-03-23 07:15
浏览 108
已采纳

如何使用Ajax和php填充可靠的下拉列表[关闭]

Hi i want to manage data on drop-down menu using Ajax.

Databse Fields:

1.id

2.name

3.department

myDesgin.php

     <select id="id"></select>
     <select id="name"></select>
     <select id="department"></select>

1.If i selected one drop-down menu want to change another drop-downs depend on selected value using Ajax.

2.Is there any code available, if i select one drop-down it go to another child window and display data as in table format(like report) using Ajax.

Thanks in Advance.

Please give me example code, because i am beginner to ajax , most welcome if someone provide explanation with code(for ajax).

  • 写回答

4条回答 默认 最新

  • dongzhang3482 2015-03-23 07:28
    关注

    Yes, check following jquery ajax code. In this example, if you change "Department" then it will populate the listing of "Name" dropdown.

    $(document).on("change", '#department', function(e) {
                var department = $(this).val();
                
    
                $.ajax({
                    type: "POST",
                    data: {department: department},
                    url: 'admin/users/get_name_list.php',
                    dataType: 'json',
                    success: function(json) {
    
                        var $el = $("#name");
                        $el.empty(); // remove old options
                        $el.append($("<option></option>")
                                .attr("value", '').text('Please Select'));
                        $.each(json, function(value, key) {
                            $el.append($("<option></option>")
                                    .attr("value", value).text(key));
                        });                                                     
                        
    
                        
                        
                    }
                });
    
            });

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)