parse xml with jquery ajax request

前端 未结 1 1073
Happy的楠姐
Happy的楠姐 2020-12-21 05:22

I have this xml document:




message 1 


        
相关标签:
1条回答
  • 2020-12-21 05:31

    Try this code:

    $(document).ready(function() {
        $.ajax({
            type: "GET",
            url: "numbers.xml",
            dataType: "xml",
            success: function(response) {
                $('lesson', response).each(function() {
                    $("#dropdownlist").append($('<option />').text($(this).text()));
                });
            }
        });
    
        $("select").change(function() {
            var str = '';
    
            $(this).find(":selected").each(function() {
                str += $(this).text() +' ';
            });
    
            $("#dropdownlist").val(str);
        }).change();
    });
    

    You were attaching a change() trigger to your element every time you looped.

    0 讨论(0)
提交回复
热议问题