I tried changing the .click to .on('click' ....) and .submit
also tried to add async: false
but it takes a second click to call success
Is there anyone who can help? I would be very grateful!
Button (Ajax Trigger)
<p>
<%= submit_tag l(:button_save), :name => nil, :id => 'time_entry_submit' %>
<%= link_to_function(l(:button_cancel), "$('#new_time_entry_form').toggle();$('#report_menu_options').toggle();".html_safe) %>
</p>
js.erb
$('#time_entry_submit').click(function(evt){
evt.stopPropagation();
evt.preventDefault();
var url = $(this).parents('form:eq(0)').attr('action');
$.ajax({
url: url,
method: 'POST',
datatype: 'json',
success: function(response) {
window.alert(response);
location.reload();
}
})
return false;
})
When I click a second time alert shows
var flashNotice = $("#flash_notice");
flashNotice.remove();
$("#flash_error").remove();
and I put the console.log inside the .click, and it appears on the second click