Here’s my JavaScript, and I’m trying to re-render a div(without reloading the page) as a partial: _change_date_range.html.erb
$(document).ready(function() {
$("#end_date_string").bind("change", function() {
var data = {date_string:$(this).val()}; // the value of input that need to send to server
$.post('<%=change_date_range_root_path %>', data, // make ajax request
function(html) { // function to handle the response
$("#resultsContainer").html(html); // change the inner html of update div
});
});
});
However, I’m rendering the default view in Rails like this, so the path needs the preceding underscore on the filename, whereas the JavaScript does not need it.
<%= render :partial => 'change_date_range', :locals => {:end_date_string => :params[:end_date_string]} %>
You need to change your js to look something like this: