我做错了什么,无法让 JQuery 将我的 xml 文件读入 DDL?
当用户选择两个单选按钮之一时,尝试将数据加载到下拉列表中。 bookGenres.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:
$('#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" ); }
});
});
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. I'm out of ideas.
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:
$('#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" ); }
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Justen,
最可能的问题是 bookgenres.xml 可能与脚本位于同一文件夹中,但它与 jQuery 正在更新的 html 页面位于同一文件夹中吗?
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?