简体   繁体   English

我无法让JQuery将xml文件读入DDL时,我在做什么错?

[英]What am I doing wrong that I can't get JQuery to read my xml file into a DDL?

Trying to load data into a drop down list when a user selects one of two radio buttons. 当用户选择两个单选按钮之一时,尝试将数据加载到下拉列表中。 the bookGenres.xml file is in the same directory as my script. bookGenres.xml文件与我的脚本位于同一目录中。 I'm out of ideas. 我没主意了。

XML: XML:

<?xml version="1.0" encoding="utf-8" ?>
<Genres>
  <Fiction>
    <book>Sci-Fi</book>
    <book>Fantasy</book>
    <book>Horror</book>
    <book>Romance</book>
    <book>Detective</book>
  </Fiction>
  <NonFiction>
    <book>Autobiography</book>
    <book>Philosophy</book>
    <book>Cooking</book>
    <book>Historic</book>
    <book>Teaching</book>
  </NonFiction>
</Genres>

JQuery: jQuery的:

$('#rblGenre').click( function() {
        $('#ddlSpecificGenre > option').remove();

        $.ajax({
            type: 'GET',
            url: 'bookGenres.xml',
            dataType: 'xml',
            success: function( xml ) {
                $(xml).find( $(this).val() ).each( function() {
                    var subgenre = $(this).find('book').text();
                    $('#ddlSpecificGenre').append( "<option>" + subgenre + "</option>" );
                });
            },
            error: function() { alert( "WTF" ); }
        });
    });

Justen, 贾斯汀,

The most likely issue is that the bookgenres.xml might be in the same folder as the script, but is it in the same folder that the html page is that the jQuery is getting renered on? 最可能的问题是bookgenres.xml可能与脚本位于相同的文件夹中,但是jQuery是否在html页面上位于同一文件夹中?

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

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