3
I’m doing a search in my BD to verify the existence of email, avoiding the registration of the same again, but I’m having problem in return, the script below sends and treats the return.
if (sender.getFieldName() == 'Email') {
if (sender.getValue()) {
var emailExist = false;
$.ajax({
type: 'GET',
url: 'AjaxBasedValidation.php',
data: {
checkEmail: sender.getValue()
},
async: false,
dataType: 'json',
success: function(dataResult) {
emailExist = dataResult;
}
});
editors['Email']
.setState(emailExist ? 'warning' : 'success')
.setHint(emailExist ? 'E-mail ' + sender.getValue() + ' já está cadastrado' : null);
} else {
editors['Email']
.setState('normal')
.setHint(null);
}
}
The code you check in the BD:
#Recebe o Email Postado $emailPostado = $_GET['checkEmail']; #Conecta banco de dados $con = mysqli_connect(".", "", "", ""); $sql = mysqli_query($con, "SELECT * FROM `usuarios` WHERE `Email` = '{$emailPostado}'") or print mysql_error(); if($rcQuery == true){ die('{"dataResult" : 0"}'); } else { die('{"dataResult" : 1"}'); }
All emails I inform the script is accusing that are already registered.
Hello @rray, I edited the question after your reply, thanks for the tip, I will test.
– adventistapr
@adventistapr remember to convert the return of ajax into json,
var retorno = JSON.parse(dataResult)
, then you can use.console.log(retorno.dataRresult);
– rray
Hello @rray, could you give me an example of how to convert the return of ajax to json? I did it the way you gave me, but I don’t know if I did it right. I appreciate it.
– adventistapr
@adventistapr what happened:? gave error?
– rray
Hello @rray, still accuses that all e-mail are already registered
– adventistapr
@adventistapr in javascript if you do
console.log(dataResult);
shows what?– rray
Hello @rray, thanks for the help, I redid the search and debugged the script, now everything is correct. Was missing in the return php, thanks for the hints.
– adventistapr
@adventistapr tranquil ;) q good q hit the code
– rray