在 rails 中使用与本地和远程相同的形式进行过滤
Using same form as local and remote both in rails for filtering purposes
场景:
我有一个可以进行过滤的表单。为了简单起见,假设我有一个包含三个输入选项的表单:
<%= form_tag(some_path,method: :get) do %>
#..checkboxes for option 1
#..radiobuttons for option 2
#..checkboxes for option 3
<%= submit_tag "submit" %>
<% end %>
<p>You have a total of: COUNT results.</p>
要求输出:
我想要的是当用户点击任何复选框或单选按钮(本质上是任何输入字段中的更改)时的功能,ajax 请求应该生成到 returns 总结果的 COUNT,我将使用返回的计数更新 p 标签内的 COUNT。
并且当用户点击提交按钮时,应该生成默认的 GET 请求。
我为 ajax 请求添加了这个脚本,它工作得很好。
<script>
$(".option").change(function(){
var type = $("input[name='type[]']:checked").map(function () {
return this.value;
}).get();
$.ajax({
url: "/gre",
type: "put",
dataType: "json",
data: {custom: 'true',type: type},
success: function (response) {
var count = response["count"];
$('#count').html('Your session will have a total of '+ count + ' questions.');
}
});
});
场景:
我有一个可以进行过滤的表单。为了简单起见,假设我有一个包含三个输入选项的表单:
<%= form_tag(some_path,method: :get) do %>
#..checkboxes for option 1
#..radiobuttons for option 2
#..checkboxes for option 3
<%= submit_tag "submit" %>
<% end %>
<p>You have a total of: COUNT results.</p>
要求输出:
我想要的是当用户点击任何复选框或单选按钮(本质上是任何输入字段中的更改)时的功能,ajax 请求应该生成到 returns 总结果的 COUNT,我将使用返回的计数更新 p 标签内的 COUNT。
并且当用户点击提交按钮时,应该生成默认的 GET 请求。
我为 ajax 请求添加了这个脚本,它工作得很好。
<script>
$(".option").change(function(){
var type = $("input[name='type[]']:checked").map(function () {
return this.value;
}).get();
$.ajax({
url: "/gre",
type: "put",
dataType: "json",
data: {custom: 'true',type: type},
success: function (response) {
var count = response["count"];
$('#count').html('Your session will have a total of '+ count + ' questions.');
}
});
});