I’m trying to figure out how to submit my form with a page refresh. I’m creating a small dealer locator for a client, and when my form submits, they update the dealer list fine. What I’m trying to do is have it so the page doesn’t reload. So far I’ve written the following code, but not sure how to post the variable and have it take effect by my Ruby on Rails code.
$("#getDealers ").submit(function(e) {
e.preventDefault();
// pull in postal code variable
});
You could use the
.serialize()method to send the contents of the form using AJAX to the corresponding action as if it was normal request:And to avoid writing all this code you could use the excellent jquery form plugin: