I’m using .submit() method to send data.
What I have is a question form with alternatives, when I click on one it automatically updates on the DB using this:
application.js
function save_response_with_ajax(t){
$('#edit_response_set_' + t).submit();
}
and the radio button is this:
<%= rs_a_form.input :answer_id,
:collection => "code that gets the info",
:as => :radio,
:input_html => {
:onclick => 'save_response_with_ajax(' + response_set.id.to_s + ');'} %>
Everything works fine, but when I click a lot of times that radio button, the form renders again so I was looking how to avoid multiple ajax requests (only one even if I click a lot of times) and I have to use $.ajax() method.
The problem is when I write :
function save_response_with_ajax(t){
$("#form").submit(function(){
//it suppose to be $.ajax(url, .....) instead of alert
// I'm just testing
alert("hi");
});
}
nothing happens.
Hope someone can help me
To avoid multiple submits, you can use global ajax event handlers to trigger functions when AJAX requests start and end etc.