I am trying to make an ajax call using the below jQuery.
But I can see in Chrome, i’m getting uncaught typeerror cannot read property ‘error’ of null. So this stops the class (‘success’) getting added. Any idea why it’s doing this? Do I somehow need to declare ‘error’??
function submitForm(formData) {
$.ajax({
type: 'POST',
url: 'mailer.php',
data: formData,
dataType: 'json',
cache: false,
timeout: 7000,
success: function(data) {
$("form #form_ajax").removeClass().addClass((data.error === true) ? "error" : "success")
.html(data.msg).fadeIn('fast');
if ($('form #form_ajax').hasClass('success')) {
setTimeout("$('form #form_ajax').fadeOut('fast')", 5000);
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
$('form #form_ajax').removeClass().addClass('error')
.html('<p>There was an ' + errorThrown + 'error due to a ' + textStatus + ' condition.</p>').fadeIn('fast');
},
complete: function(XMLHttpRequest, status) {
$('form')[0].reset();
}
});
};
Thanks…
edit your code to :
and tell me the alert msg (theres 2)
EDIT : its not make any sense:
do this :