jeudi 2 avril 2015

Ajax success data empty on second try?

On click of the form-submit button, an ajax-request will be sent to a php-handler. Well, the request ist sent as it should, I even get my answr from the php-file, but, after getting "The text has to be between 50 and 5000 characters." once, the next time I click my submit butten, the ajax succes() data will stay empty. Why?


AJAX:



<script>
$("#formID").submit(function(){
$.ajax({
url: $(this).attr('action'),
type: $(this).attr('method'),
data: $(this).serialize(),
beforeSend:function(){
$('#sendBox').html('<div class="loading"><img src="ajax-loader.gif" alt="Loading..." /></div>');
},
success: function(data)
{
$("#sendBox").html(data);
$("#sendBox").show('slow');
if(data.substr(0,8) == "(Contact)"){
document.getElementById("formID").reset();
}
}
});
return false;
});
</script>


This is my php-handler:



if(strlen($_POST["fName"]) < 3 || strlen($_POST["fName"]) > 30){
return LangText("Der Name muss zwischen 3 und 30 Zeichen sein.", "Le nom doit étre entre 3 ét 30 charactéres.", "The name has to be between 3 and 30 characters.");
}else if (!filter_var($fMail, FILTER_VALIDATE_EMAIL)) {
return LangText("Die E-Mail Adresse ist nicht richtig.", "Votre adresse électronique n´est pas valide", "Your email adress is not valid");
}else if(strlen($_POST["fText"]) < 50 || strlen($_POST["fText"]) > 5000){
return LangText("Der Text muss zwischen 50 und 5000 Zeichen sein.", "Le text doit étre entre 50 ét 5000 charactéres.", "The text has to be between 50 and 5000 characters.");
}else {
//send email
echo LangText("(Contact) Vielen Dank, sie haben uns kontaktiert.", " (Contact) Merci beaucoup, vous nous avez contacté.", "(Contact) Thank you, your email has been sent.");
}

Aucun commentaire:

Enregistrer un commentaire