gpt4 book ai didi

javascript - AJAX日历更新页面rails 4

转载 作者:行者123 更新时间:2023-11-28 08:27:04 24 4
gpt4 key购买 nike

我正在使用 jQuery 的日期选择器来显示日历。当用户单击某个日期时,页面应呈现该特定日期的有效信息(在本例中为可用座位表)。

我可以看到我的日期在更改时通过 AJAX 传递,但模板从未被渲染。部分如何知道从 Controller 获取@schedule?我做错了什么?

查看

<p>
Date:
<%= text_field "Date", "", :class => 'datepicker'%>
</p>

js

$(document).ready(function() {
if($('.datepicker').length){
$('.datepicker').datepicker({
dateFormat: 'yy-mm-dd'
});

}

$('.datepicker').change(function(){

$.ajax({
data: {Date: $('.datepicker').val()},
})
});
});

Controller

def show
return unless @product

@variants =
@product.variants_including_master.active(current_currency).includes([:option_values,
:images])

@product_properties = @product.product_properties.includes(:property)


@schedule = FlightSchedule.where(:date => params[:Date]).available_slots

respond_to do |format|
format.html
format.js
end

referer = request.env['HTTP_REFERER']
if referer
begin
referer_path = URI.parse(request.env['HTTP_REFERER']).path
# Fix for #2249
rescue URI::InvalidURIError
# Do nothing
else
if referer_path && referer_path.match(/\/t\/(.*)/)
@taxon = Spree::Taxon.find_by_permalink($1)
end
end
end
end

js.erb

$('#seat_table').html('<%= escape_javascript render("seat_table")%>');

部分

<table>
<th> Available Times </th>
<th colspan='5'> Available Seats </th>
<% @schedule.each do |available| %>
<tr>
<td>
<%= available.time.strftime("%l:00") %>
</td>
<% @product.variants_and_option_values.each_with_index do |variant, index| %>

<td>
<% if available.seat_available?(available, variant.option_value('seat')) %>
<%= check_box_tag "variants[#{variant.id}]", "1" %>
<label for="<%= ['variants', @product.id, variant.id].join('_') %>">
<span class="variant-description">
<%= variant.option_value('seat') %>
</span>
</label>
<% else %>
<label for="<%= ['variants', @product.id, variant.id].join('_') %>">
<span class="variant-description">
<%= variant.option_value('seat') %>
</span>
</label>
<% end %>
</td>

<% end %>
</tr>
<% end %>
</table>

日志的开头;日期正在传递并且正在调用正确的操作。

    Started GET "/products/flight-simulation?Date=2014-03-31" for 127.0.0.1 at 2014-03-09 14:57:57 -0400
Processing by Spree::ProductsController#show as */*
Parameters: {"Date"=>"2014-03-31", "id"=>"flight-simulation"}

最佳答案

我可以立即看到的一件事是您缺少数据类型。

改变

$('.datepicker').change(function(){

$.ajax({
data: {Date: $('.datepicker').val()},
})
});

$('.datepicker').change(function(){

$.ajax({
data: {Date: $('.datepicker').val()},
dataType : 'script'
})
});

关于javascript - AJAX日历更新页面rails 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22286823/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com