Why isn't the javascript error message working?

It’s picking up the php error code, but not the javascript. It worked before, but then I did something and it doesn’t work anymore.

$(function() {

	// Get the form.
	var form = $('#ajax-contact');

	// Get the messages div.
	var formMessages = $('#form-messages');

	// Set up an event listener for the contact form.
	$(form).submit(function(e) {
		// Stop the browser from submitting the form.
		e.preventDefault();

		// Serialize the form data.
		var formData = $(form).serialize();

		// Submit the form using AJAX.
		$.ajax({
			type: 'POST',
			url: $(form).attr('action'),
			data: formData
		})
		.done(function(response) {
			// Make sure that the formMessages div has the 'success' class.
			$(formMessages).removeClass('error');
			$(formMessages).addClass('success');

			// Set the message text.
			$(formMessages).text(response);

			// Clear the form.
			$('#name').val('');
			$('#email').val('');
			$('#message').val('');
		})
		.fail(function(data) {
			// Make sure that the formMessages div has the 'error' class.
			$(formMessages).removeClass('success');
			$(formMessages).addClass('error');

			// Set the message text.
			if (data.responseText !== '') {
				$(formMessages).text(data.responseText);
			} else {
				$(formMessages).text('One or more field(s) is missing.');
			}
		});
	});
});

It’s impossible to tell from what you’ve posted. Are there any error messages in the console? What’s the network tab saying?

If you can provide a succinct example that people can run that reproduces your error, you’ll stand a much better chance of getting a helpful answer.

1 Like

yes there is an error message, but it’s picking up the php error message instead of the javascript error message. The error message suppose to have a red background.

Sorry I forgot to post my website. http://f6-preview.awardspace.net/thegroupeezz.dx.am/groupeezz11/index.html

imgur link doesn’t work.

Looking at your site in the console I see:

Failed to load resource: the server responded with a status of 404 (Not Found) 
http://f6-preview.awardspace.net/thegroupeezz.dx.am/groupeezz11/js/jquery.creative.js 

Uncaught SyntaxError: Unexpected token ILLEGAL
index.html:270 

You’ll want to sort those out I imagine.

Thank you! I fixed it, but the error message still remains the same and its still green and not red.

You didn’t :frowning:

i removed the creative.javascript

I don’t get what unexpected token illegal means.

http://f6-preview.awardspace.net/thegroupeezz.dx.am/groupeezz11/index.html

What’s on line 270?

This was the code I got from mailchimp.

Well you seem to have fixed that now (it was a stray single quote). Does the problem still persist?

If so, can you provide instructions of how we can reproduce it.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.