如何在ajax url中调用控制器动作

编程入门 行业动态 更新时间:2024-10-19 14:48:31
本文介绍了如何在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中调用控制器动作

本文发布于:2023-11-24 21:03:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626812.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制器   动作   如何在   url   ajax

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!