javascript - Check email if exist using ajax -


basically, want check email if exist in db automatically. function not work when connection.php & mysqli queries inserted.

html:

<input type="email" name="email" class="formemail"> 

js:

  $( document ).ready(function() {     $('.formemail').on('change', function() {         //ajax request         $.ajax({             url: "queries/checkemail.php",             data: {                 'email' : $('.formemail').val()             },             datatype: 'json',             success: function(data) {                 if(data == true) {                     alert('email exists!');                 }                 else {                     alert('email doesnt!');                 }             },             error: function(data){                 //error             }         });     });   }); 

php:

require_once("../connection.php");  $useremail = $_get['email'];  $checkemail=mysqli_query($con, "select email accounts email='$useremail'");  if (mysqli_num_rows($checkemail) == 1) {   $response = true; } else {   $response = false; }  echo json_encode($response); 

you made small mistake in getting response in if condition in success block of ajax call function.

rewrite date data in if condition

$( document ).ready(function() {     $('.formemail').on('change', function() {         //ajax request         $.ajax({             url: "queries/checkemail.php",             data: {                 'email' : $('.formemail').val()             },             datatype: 'json',             success: function(data) {                 if(data == true) {                     alert('email exists!');                 }                 else {                     alert('email doesnt!');                 }             },             error: function(data){                 //error             }         });     }); }); 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -