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条)

报告相同问题?