Answer the question
In order to leave comments, you need to log in
How to render select on ajax request?
The bottom line is this: I select the first one select
and, depending on the value value
(from the first select), I build the second one select
. those. I send a get-request with a parameter code
to the controller and I want to receive the array I need in response. I need to get data from a controller.
The data is sent to the controller. There, on the basis of this data, I have an array The @point
question is: How to render now this in a view. In partial, @point
there is a variable with the desired values (when I chose the city). More like using js
it to render.
My JS:
$(document).ready(function () {
$('#country_id').change(function () {
var country_id = $(this).val();
$('#region_id').attr('disabled', true);
$('#region_id').html('<option>загрузка...</option>');
$.get(
'/baskets',
{ code: country_id },
function (result) {
if (result.type == 'error') {
alert('error'); js
return(false);
}
else {
// вот эта часть не рендерится
$('<%= j(render :partial => "points", :locals => {:point => @point}) -%>').appendTo('#country_id');
$('#region_id').attr('disabled', false);
}Паршл point
},
"json"
);
});
});
js
<form action="/baskets" >
<p>Город</p>
<select name="country_id" id="country_id">Паршл point
<option value="0">- выберите город -</option>
<% @city.sort.each do |city| %>
<option value="<%=city[1]%>"><%= city[0] %> </option>
<% end %>
</select>
<br><br>
<p>Пункт выдачи:</p>
<%= render :partial => 'points', :locals => {:point => @point} %>
</form>
<select name="region_id" id="region_id" disabled="disabled">
<option value="0">- выберите пункт -</option>
<% @point.sort.each do |point| %>
<option value="<%=point[1]%>"><%= point[0] %> </option>
<% end %>
</select>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question