php - Email Validation is not working in jQuery -


guys want validate email address in php file "validate.php". not working. not getting response "validate.php" file.

jquery code:

function validate_email(email){           $.post('validate.php', {email:email}, function(data){                 $('msg').text(data);             }); }  $('#input').focusin(function(){    if($('#input').val() === ''){      $('#msg').text("enter valid email address");   }   else{        validate_email($('#input').val());   }          }).blur(function(){              $('#msg').text(""); }).keyup(function(){             validate_email($('#input').val());       }); 

"validate.php" code:

<?php if(isset($_post['email'])){     $email = $_post['email'];      if(!empty($email)){    if(filter_var($email, filter_validate_email) === false)           echo 'email address not valid, enter valid email address.';    else           echo 'email valid. mubarak ho!';     }   } ?> 

check error log because code work on server

this code test

html part

<input id="email" type="email" value="dinhphong.developer@gmail.com"> <button>submit</button>  <script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>  <script>  $(document).on('click', 'button', function() {     var email = $('#email').val();     console.log(email);     $.post('validate.php', {email:email}, function(data){        console.log(data);     }); })  </script> 

php part

if(isset($_post['email'])){     $email = $_post['email'];      if(!empty($email)){    if(filter_var($email, filter_validate_email) === false)           echo 'email address not valid, enter valid email address.';    else           echo 'email valid. mubarak ho!';     } } 

my advice:

  • at $('msg').text(data); should $('#msg').text(data);

  • f12 check error log of javascript

  • check php path on ajax f12 -> network -> xhr , check status (if use chrome)

  • if status == 200 (it mean ok) click validate.php check response php file

  • don't forget feedback if fixed bug can guy have same bug you


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -