I have an html file in which users can enter a value. I wrote a script in PHP that checks if this value is present in the database. If it is present, it returns
{"active": true}
Now my goals are that when the user enters their value and sends them, they will be redirected to a specific page if it is active. If it is wrong, they should see an error message.
So here is what I tried with my AJAX call:
$("document").ready(function(){
$(".checkform").submit(function(e){
e.preventDefault();
$.ajax({
type: "GET",
dataType: "json",
url: "api/check.php",
data: data,
success: function(data) {
if(data.active=="true"){
alert("success");
location.href="where_you_want";
}else{
alert("failure");
}
}
});
return false;
});
});
Here is my HTML:
<form action="api/check.php" id="requestacallform" method="GET" name="requestacallform" class="formcheck">
<div class="form-group">
<div class="input-group">
<input id="#" type="text" class="form-control" placeholder="Jouw subdomein" name="name"/>
</div>
</div>
<input type="submit" value="Aanmelden" class="btn btn-blue" />
</form>
For some reason, I get an error:
Uncaught ReferenceError: data not defined
I'm new to AJAX and I'm not sure if I'm trying correctly. Any help would be greatly appreciated!
Thanks in advance.