I am trying to implement a form_tag in rails 3 that can be submitted using ajax instead of html through javascript. Despite setting the form to submit as javascript, it still submits as html when clicking the submit button.
- form_tag({:controller => "checkin", :action => "main_page"}, :remote => true, :method => :get, :id => "get_location_form" ) do
Latitude:
= text_field_tag 'latitude_field', '', :size => 10, :class => 'submittable'
Longitude:
= text_field_tag 'longitude_field', '', :size => 10, :class => 'submittable'
= submit_tag "Send Info"
In addition, I have included jQuery functions in my application.js file:
$(document).ready(function() {
$("#get_location_form").submitWithAjax();
});
jQuery.fn.submitWithAjax = function() {
this.submit(function() {
$.post(this.action, $(this).serialize(), null, "script");
return false;
});
return this;
};
I am facing an issue where manually pressing the submit button triggers a javascript request, but using form.submit() in javascript results in an HTML request being sent.
If you have any insights into why this may be happening, your help would be greatly appreciated.