简体   繁体   中英

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

$(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

Use 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;
    }
})
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM