jQuery使用AJAX更改下拉菜单 [英] jQuery to change dropdown with AJAX

查看:101
本文介绍了jQuery使用AJAX更改下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个单选按钮来更改下拉菜单,如果不能正常工作,则可以确保大多数情况,但不确定几件事.我想将CreativeID作为ID,并将CreativeName作为名称.这是我的AJAX:

I need a radio button to change a dropdown and have most if it working just not sure about a few things. I want to have CreativeID as the ID and CreativeName as the name. Here's my 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是值,并且产品名称显示在选项标签之间. 任何帮助,将不胜感激!

My Question: I just have no idea how to populate the dropdown so the ID is the value AND the product name shows between the option tags. Any help on this would be appreciated!

推荐答案

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>');
}

这篇关于jQuery使用AJAX更改下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆