I have this as my view page
<html>
<head>
<script>
function submit_form()
{
$('#my_form').submit();
}
</script>
</head>
<body>
<div class="container">
<%= form_tag({:action => 'submit_form'}, :remote => true,:method=>:post,:id => 'my_form',:class => 'my_form_class') do %>
<%= select(:grade,:id,@distinct_grade_list,{},:onchange => "submit_form()")%>
<%= select(:period,:id,@distinct_period_list)%>
<% end %>
<br/>
<div id="farzi2" style="border: 3px solid blue;margin-top: 20px">
<%= select(:student_name,:id,{},{},{ :multiple => true, :size => 4 }) %>
</div>
</body>
</html>
now when i change the content of first select box , the javascript function submits form via ajax and sends back to the controller action as mentioned in the form
in the controller action I have
def submit_form
puts "in submit_form action"
@hussi = "submit_form"
@student_name_list = Student.pluck(:student_name)
respond_to do |format|
format.html { redirect_to 'roles' }
format.json { head :no_content }
format.js { render :json => @student_name_list }
end
end
now my question is , how can i use these @hussi and @student_name_list data in the relavant js. erb file to set the contents displayed in the view page
my submit_form.js.erb file has nothing till now
alert("in submit_form js");
$('.my_form_class').on('ajax:success', function()
{
alert(<%=@student_name_list%>")
})
All I want is to use this list (@student_name_list) passed from ajax called action(submit_form) to be used in my view page for a select option box after the ajax request comes back with success .