繁体   English   中英

jQuery用AJAX更改下拉列表

[英]jQuery to change dropdown with AJAX

我需要一个单选按钮来更改下拉列表,并且如果它只是不确定一些东西,那就有最多。 我希望将CreativeID作为ID,将CreativeName作为名称。 这是我的AJAX:

$('input[name=creativeType]').change(function(){
        $.ajax({
            url: '/app/components/MailingsReport.cfc',
            //POST method is used
            type: "POST",
            //pass the data 
            data: {
                method: "getCreative",
                CreativeType: $('input[name=creativeType]:checked').val(),
                datasource: "shopping_cart"
                 },
            dataType: "xml",
            //contentType: "application/text; charset=utf-8",
            success: function(xml){
                $('#creative option').remove();
                    $(xml).find('number').each(function()
                    {

$("#creative").append('<option value="' + $(this).text() + '">' + $(this).find('CREATIVENAME').text() + '<\/option>');

                    });                
            }
        });

这是我的返回数据:

<wddxPacket version='1.0'><header/><data><recordset rowCount='3' fieldNames='CREATIVEID,CREATIVENAME' type='coldfusion.sql.QueryTable'><field name='CREATIVEID'><number>52.0</number><number>65.0</number><number>77.0</number></field><field name='CREATIVENAME'><string>Product One</string><string>Product Two</string><string>Product Three</string></field></recordset></data></wddxPacket>

我的问题:我根本不知道如何填充下拉列表,因此ID是值和产品名称显示在选项标签之间。 任何有关这方面的帮助将不胜感激!

var numbers = $(xml).find('number');
var strings = $(xml).find('string');
for (var i = 0; i < numbers.length; i++) {
    $("#creative").append('<option value="' + numbers[i].innerHTML + '">' + strings[i].innerHTML + '<\/option>');
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM