I have a registerpage,a emailvalipge,indexpage, I want to check the existence of the email account.
It worked fine before. But it’s not working now. I suspect the $.ajax part.
1.the registerpage code:
$(document).ready(function() {
$("#email").keyup(function(){
$.ajax({
type: 'GET',
datatype: 'json',
url: "emailvali.php",
success: function(data) {
var tmp=document.getElementById("email").value;
var dataArr = eval(data);
var count=0;
for (var i=0; i<dataArr.length; i++)
{
if (dataArr[i] == tmp)
{
count=1;
}
}
if (count==1)
{
$("#marker").html("email exists.");
document.getElementById("check").value = 2;
}
else
{
$("#marker").html("");
document.getElementById("check").value = 1;
}
},
error: function() {
alert("json reload fail");
}
});
});
});
<input type="text" name="email" id="email">
<span id="marker"></span>
- emailvalipage code:
<?php
error_reporting(E_ALL & ~E_NOTICE);
include $_SERVER['DOCUMENT_ROOT'] . '/includes/db2.inc.php';
try
{
$result = $pdo->query('SELECT email FROM users');
}
catch (PDOException $e)
{
$error = 'error fetching email.';
include 'error.html.php';
exit();
}
foreach ($result as $row)
{
$emails = array($row['email']);
}
echo json_encode($emails);
?>
before, When I typed in a exist email account, at the part it shows “email exists”. now it shows nothing, I test the count value, it’s always gonna be 0. The database part,sql part should be correct.
Does anyone know what’s the possible error?