View Full Version : Trouble with Form Submission..

01-28-2012, 02:17 AM
I am trying to submit my form and receive a success message that go's away.
My form validation is working fine and I receive the email, but the echo back to json is giving my error message instead of my success message. This is my first try doing this and am brand new to javascript. If anyone could please help me figure out what is wrong or tell me how to rewrite it, I would be much obliged.

function submitForm(formData) {

type: 'POST',
url: 'bookings.php',
data: formData,
dataType: 'json',
cache: false,
timeout: 7000,
success: function(data) {

$('form #response').removeClass().addClass((data.error === true) ? 'error' : 'success')

if ($('form #response').hasClass('success')) {

setTimeout("$('form #response').fadeOut('fast')", 5000);

error: function(XMLHttpRequest, textStatus, errorThrown) {

$('form #response').removeClass().addClass('error')
.html('<strong>There was an error. Please use the above information and contact us directly.</strong>').fadeIn('fast');
complete: function(XMLHttpRequest, status) {


01-29-2012, 12:28 AM
You'll have to make sure that the response from the server is REALLY json. You can do this by assuring to output the proper json formatted string AND by giving the PHP header as "Content-type: application/json"