Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2010
    Posts
    12
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Trouble with Form Submission..

    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.

    Code:
    function submitForm(formData) {
    	
    	$.ajax({	
    		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')
    						.html(data.msg).fadeIn('fast');	
    						
    			
    			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) { 			
    			
    			$('form')[0].reset();
    		}
    	});	
    };

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    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"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •