Yisroel Arnson Yisroel Arnson - 4 years ago 63
PHP Question

.done ajax giving me an error

So I'm creating a contact form that sends an email using ajax and PHP.

I Seem to get an error when i run this script.

error: Uncaught Syntax Error: Unexpected token .

using chrome BTW.

I also have a PHP file, but i don't think that is relevant, i can add it if needed.

$(function() {
var form = $('#ajax-contact');
var formMessages = $('#form-messages');
var formData = $(form).serialize();

$(form).submit(function(event) {

type: 'POST',
url: $(form).attr('action'),
data: formData

.done(function(response) {



.fail(function(data) {

if (data.responseText !== '') {
} else {
$(formMessages).text('Oops! An error occured and your message could not be sent.');

Answer Source

This is happening because you are terminating the ajax call by putting a semicolon and after that you are calling .done(). The correct syntax is:

$.ajax( "..." )
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download