display messages from server in my contact form with jQuery Ajax and JSON
hello everyone i habe a problem to display my successes and errors messages in Browsers Firefox and IE. my messages are displaying in a different browser window and not in he set Tags from my html.
Here you can see my code:
- $('#abschicken').click(function() {
- event.preventDefault();
-
- // get the form data
- var formData = {
- 'name' : $('input[name=name]').val(),
- 'email' : $('input[name=email]').val(),
- 'tel' : $('input[name=tel]').val(),
- 'bemerkung' : $('textarea[name=bemerkung]').val()
- };
-
- // process the form
- $.ajax({
- type : 'POST',
- url : 'phpmailer/index.php',
- data : formData,
- dataType : 'json',
- encode : true
- })
- // process the form
- .done(function(data) {
- // log data
- console.log(data);
- // handle errors and validation results
- if (!data.success) {
- // handle errors for name ---------------
- if (data.errors) {
- $('#name').addClass('has-error'); // add the error class to show red input
- $('div#result').addClass('error').html(data.errors); // add the actual error result under our input
- }
- // handle errors for email ---------------
- if (data.errors) {
- $('#email').addClass('has-error'); // add the error class to show red input
- $('div#result').addClass('error').html(data.errors); // add the actual error result under our input
- }
- if (data.errors) {
- $('#tel').addClass('has-error'); // add the error class to show red input
- $('div#result').addClass('error').html(data.errors); // add the actual error result under our input
- }
-
- } else {
- $('#contact-form').slideUp( "slow", function(){
- $('div#result').removeClass('error');
- $('div#open-window').addClass('success').html(data.success);
- // $('div#open-window').addClass('success').append( "<p>Danke, wir rufen Sie an.!</p>" );
- $('.close-window').css('display', 'inherit');
- });
- }
- if (data.complete){
- $('#divMsg').hide();
- }
- })//done function
-
- });//click button
in my PHP script is everything right otherwise i could receive any answer messages from server. i don't really know, where is the problem :-( i appreciate
any helps! Thank you!