Reputation: 2881
I have a AJAX form in Rails 3. Given the nature of my app, I need to call .submit()
on the form programatically. But before the AJAX request is sent to the server, I want to perform some client side logic on the form data. And in this logic, I add hidden input fields inside the form being submitted.
So I have two questions:
Thanks.
UPDATE -- I answered question 1 by using the .submit() event handler. But it looks like the hidden input field I add to the form in that logic is not being sent in the POST request. Any ideas on how I can overcome this?
Upvotes: 0
Views: 662
Reputation: 15492
Its quite simple, you can use the jQuery .submit() event handler as well.
$('form_selector_here').submit(function() { // pre process form here, add fields using $.append() etc $(this).ajaxSubmit(); // or $.ajax({ // settings here; }) })
For .ajaxSubmit() , you need to use the Jquery Form Plugin http://jquery.malsup.com/form/#getting-started
Upvotes: 1