我怎样才能刷新一个细节选择列表时,我的主人选择使用AJAX的变化 [英] How can I refresh a detail select list when my master select changes using AJAX
问题描述
我在找一些指针。我有一个选择列表中的主题列表;
I'm looking for some pointers. I have one select list with a list of topics;
<select class="editor-select" id="TopicDescription" style="width: 99%">
<option value="test1">test01</option>
<option selected="selected" value="test2" >test02</option>
</select>
和子课题另一份清单:
<select class="editor-select" id="SubTopicDescription" style="width: 99%">
<option value="sub1">sub01</option>
<option value="sub2">sub02</option>
</select>
在第一个列表值的变化,我想能够刷新第二个选择列表。问题是我不知道如何做到这一点。我想用AJAX,但是这可能吗?对我来说有什么建议(出发点)将是非常美联社preciated。
When the first list value changes I would like to be able to refresh the second select list. The problem is I've no idea how to do this. I would like to use AJAX but is it possible? Any suggestions (starting point) for me would be much appreciated.
推荐答案
您需要创建一个控制器动作,将采取从第一个列表中的值,并提供一个选项列表的第二个列表。然后你就可以调用Ajax使用JavaScript框架,例如JQuery的:
You will need to create a controller action that will take in a value from the first list and supply a list of options for the second list. Then you can make an ajax call using a Javascript framework such as JQuery:
$('#TopicDescription').change(function() {
// make AJAX call to update the second select list
$.ajax({
url: "path/to/your/action",
data: $('#TopicDescription').val(),
success: function(data){
// do something to your other dropdown
// for example if your getting the data back to fill it with from your post method
$('#SubTopicDescription').html(data); // you get the point
}
});
});
这篇关于我怎样才能刷新一个细节选择列表时,我的主人选择使用AJAX的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!