Sinatra - Ajax Web Form Problems

Hello all, I’m hoping someone could help me I’m really getting nowhere
with this.

I have a form that submits info to a mysql database and it seems to
work. The data is submitted but my problem is with the ajax. Once
submitted I’d like the form to disappear and a “success” message to show
up but I’m having problems. Here is the code from my Sinatra app.

class Contact
include DataMapper::Resource
property :id, Serial
property :full_name, String
property :email, Text
property :subject, Text
property :body, Text
property :date, DateTime

database.table_exists?(Contact) or


And the form response is here:
post ‘/’ do
contact=Contact.create(:full_name => params[:fullname], :email =>
params[:email], :subject => params[:subject], :body => params[:message],
:date =>
redirect (’#/’)

Here is the web form:


And I have the following javascript validating the form - which works -
but on submit I’d like the form to disappear and a “success” message to

I’ve tried adding in other code but to no avail. If someone could start
me off int he right direction I’d appreciate it, I’m just not having any
luck. Really…thanks in advance.

Try returning something other than a redirect. The onSuccess callback
will only be executed if the response code is a success (200) and im
not sure if it will run the onSuccess when the response is a redirect

Hey Kyle, thanks for the tip but that didn’t seem to work. When
onSuccess it doesn’t work, nothing happens when I hit the submit button
when I use chrome or firefox.