I have an <input>
tag in my form:
<input type="email" name="Email_i" placeholder="enter email here" id="e_mail" onBlur="loadDoc(this.value)">
After the input loses focus, the following function is called that uses AJAX:
<script>
function loadDoc() {
var no = document.getElementById("e_mail").value;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("check").innerHTML = xhttp.responseText;
}
};
xhttp.open("GET", "ajax.php?email="+no, true);
xhttp.send();
}
</script>
And here is the PHP logic from ajax.php
:
<?php
session_start();
$email = $_GET['email'];
include "config.php";
$check = mysql_query("select * from registration_form where EMail ='$email' and EMail <> ''",$con);
if (mysql_num_rows($check) == 1)
{
echo '<p style="color:#ff0000">Email Already Exists</p>';
$_SESSION['email'] = "yes";
}
else
{
echo '<p style="color: #00ff00">available</p>';
}
I want to do this operation using AngularJS, that verifies the email address from the database, but it's not working. Can you help me?
Why not just use jQuery alongside Angular? The code would be much simpler. Also, please do not use the deprecated mysql. Use mysqli. The code should be essentially the same with just an 'i' added to your mysql query.
$.get("ajax.php", {email: $("#e_mail").val()}, function(){
alert("Success!");
});
Sorry, made some careless errors at first. I edited everything. I hope it works for you.