使用jquery将数据附加到选择框,数据来自webservice调用

时间:2014-06-06 18:06:23

标签: javascript jquery web-services

我有以下代码:

$(document)
    .ready(
        function() {
            $.ajax({
                type : "GET",
                url : "http://localhost:8080/RememberMeServer/rest/LifeEventService/events",
                dataType : "xml",
                success : function(xml) {
                    $(xml).find('Event').each(function() {
                        var name = $(this).find('Text').text();
                        $('#droplistevents').append($('<option/>', { 
                            value: name,
                            text : name 
                        }));
                    });
                },
                error : function(xhr) {
                    alert(xhr.responseText);
                }
        });
});

它的作用是对在该地址上运行的Web服务的get请求,并获取<Event> <Text> </Text> </Event>

中的数据

但遗憾的是我无法将该信息添加到我的html文件中的选择框中,其中包含id =&#34; droplistevents&#34;。 我做错了什么?

1 个答案:

答案 0 :(得分:-1)

这实际上有效。我在调用它的html页面中调用了错误的js。

我不删除,因为这可能有助于某人