Ajax function runs twice how can I solve this issue?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
14 views
I have a problem, the script sends the message twice to mail the first data I entered, and the second blank.
[ html-form.php ]:

<!DOCTYPE html>Ajax form


[ main.js ]:

// Sending a request $(document).ready(function() { $('#form').submit(function() { // check for emptiness filled fields. The html5 attribute required is not appropriate (not supported by Safari) if (document.form.name.value == " || document.form.phone.value == " ) { valid = false; return valid; } $.ajax({ type: "POST", url: "mail.php", data: $(this).serialize() }).done(function() { $('.js-overlay-thank-you').fadeIn(); $(this).find('input').val("); $('#form').trigger('reset'); $('#otv').load('mail.php'); }); return false; }); }); // Close popup "thank you" $('.js-close-thank-you').click(function() { // on clicking on the cross $('.js-overlay-thank-you').fadeOut(); }); $(document).mouseup(function (e) { // by clicking outside the pop-up when PC var popup = $('.popup'); if (e.target!=popup[0]&&popup.has(e.target).length === 0){ $('.js-overlay-thank-you').fadeOut(); } });


[ mail.php ]:

<?phpif($_POST['name']='' || $_POST['phone']=''){}else{$recepient = "test@gmail.com";$siteName = "Тест";$from = "test";$name = trim($_POST["name"]);$phone = trim($_POST["phone"]);$message = "Имя: $name \Телефон: $phone";$pagetitle = "Заявка с сайта \\"$siteName\\";mail($recepient, $pagetitle, $message, "Content-type: text/plain; charset=\\"utf-8\\"\ From: $from");echo 'Сообщение отправлено на '.$recepient;}?>
by | 14 views

2 Answers

0 like 0 dislike
Of course, you will ship after you send the $('#otv').load('mail.php') script, which is empty.
by
0 like 0 dislike
Well, what is it?
if($_POST['name']=" || $_POST['phone']="){
Well this is the condition

if($_POST['name']==" || $_POST['phone']=="){
by

Related questions

0 like 0 dislike
1 answer
asked May 22, 2019 by Alan-322
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked May 23, 2019 by vladimirvlodimir
0 like 0 dislike
1 answer
110,608 questions
257,187 answers
0 comments
40,796 users