[英]Page Reload WithOut Refresh in Ruby On Rails on DatePicker Select Event?
My Scenario as Follows 我的情况如下
When i change date the corresponding appointment list will change. 当我更改日期时,相应的约会列表将更改。
My Controller as Follows 我的控制器如下
def index
if (params[:appdate]!=nil)
@t=params[:appdate]
else
@t=Date.today.strftime("%m/%d/%Y")
end
end
and View as Follows 和查看如下
<h1>PatientDashBoard</h1>
Date is<%=@t%>
<%= form_tag('/patientdashboard') do %>
<table>
<tr>
<td><div id="appointmentdate"></div></td>
<%=hidden_field_tag 'appdate'%>
</tr>
</table>
<% end %>
and My application.js as follows 和我的application.js如下
$(function() {
$("#appointmentdate").datepicker({
onSelect : function(dateText, inst) {
$("#appdate").val(dateText);
var date=$("#appdate").val();
// alert(date);
$(this).parents('form:first').submit();
}
})
});
Then How to Write index.js.erb file without refreshing whole page just update the @t value can u please help me to solve this 然后如何编写index.js.erb文件而不刷新整个页面只是更新@t值,请您帮我解决这个问题
Use ajax. 使用ajax。 I didn't tested it.
我没有测试。 Let me know if any issue..
让我知道是否有任何问题。
$(function() {
$("#appointmentdate").datepicker({
onSelect : function(dateText, inst) {
$("#appdate").val(dateText);
var date=$("#appdate").val();
$.ajax({
type: "GET",
dataType: "script",
url: window.location.href,
data: { appdate: date},
});
return false;
}
})
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.