how to call controller action in ajax url

泄露秘密 提交于 2019-12-24 01:36:06

问题


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);
  }
});

In my users_controller.rb

def update_groups user_name
  # returns list of groups
end

How to call this method using ajax url?


回答1:


$("#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.....



来源:https://stackoverflow.com/questions/14133549/how-to-call-controller-action-in-ajax-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!