I have this AJAX request:
$("#searchagain_form").submit(function() {
$.ajax({
type: 'POST',
url: "/searchforward",
data: {engine: $("#engine_options").find(".on_engine").text()}
});
});
This is my form:
<%= form_for :searchagain, :url => {:controller => 'results', :action => 'searchforward'}, :html => { :id => "searchagain_form" } do |f| %>
<%= f.text_field :search, :value => @search, :id => 'searchagain_bar' %>
<%= f.submit :value => "search!", :id => 'searchagain_submit' %>
<% end %>
However, checking my logs, the data does not seem to be POSTed to the server when the form is submitted. Any idea why?
You did not cancel the submission, so the page will unload instead of sending the ajax-request.
Append a
return false;to the function.But however, it’s not clear what kind of element
#engine_options .on_engineis, if it is an text-input useval()instead oftext()(text() should return nothing for text-inputs).When it is a textarea it will return the textNode inside the element, not any later modified text. So use val() also for textarea.