本文介绍了如何在ajax url中调用控制器动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在ajax url中调用controller方法,以基于另一个下拉列表中的值动态填充下拉列表.我得到的值是字符串,当我使用ajax url调用此方法时,它始终指的是"show"方法.我的ajax电话
I want to call the controller method in ajax url to dynamically populate the dropdown based on value from another dropdown. The value I am getting is string, when I call this method using ajax url it always refers to 'show' method. My ajax call
$('#users').change(function() { url: '/users/update_groups', data: {name: $(this).val()}, success: function (data) { alert(data); } });在我的users_controller.rb
In my users_controller.rb
def update_groups user_name # returns list of groups end如何使用ajax网址调用此方法?
How to call this method using ajax url?
推荐答案$("#users").change(function() { $.ajax({ url: "users/update_groups", type: "POST", data: {name: $(this).val()}, success: function (data) { alert(data); } }); });
尝试上面的代码可能会起作用,然后让我知道.....如果不起作用,将尝试以其他方式提供帮助.....
try the above code once it may work and let me know.....will try to help some other way if it don't work.....
更多推荐
如何在ajax url中调用控制器动作
发布评论