I would like to check if an email address exists in ajax but I have a problem with my request. Here is the html code
<form method="post" action="" id="form_email" class="form_email" >
<label class="form_et">Email <span class="etoile">*</span></label>
<input type="email" id="email" name="email">
<button type="button" id="btn_valider"
onClick="
$(document).ready(function() {
var mail = $('#email').val();
function controler(form) {
var DATA = form;
DATA += 'action=checkMail';
$.ajax({
type: 'POST',
url: 'ajax.php',
data: DATA,
success: function(data){
console.log(data);
}
});
}
controlEmail(mail);
});">Verify</button>
</form>
And my ajax.php
if (isset($_POST['action']) &&$_POST['action'] == "checkMail") {
$test = "test";
return $test;
}
I pass well in the success, if I make a console.log ('success'), it is displayed. But with the current code, console.log (data) returns an empty line in console.
Why does not it work? If I change the url and add the error function, I go through the error. I do not understand what is happening