I am trying to access a PHP function from an ajax call but I am running into all sorts of issues since is my first time doing something like this. I need help creating the function or fixing the one I have.
This is my ajax call (I will only post a small part of it since the complete function is irrelevant to the question)
$.ajax({
type : 'post',
url : 'data.php?action=checkname',
data : {'location':locationName},
error : function(data,status,error){
console.log(data+': '+status+': '+error);
},
success : function(res){
console.log(res);
}
});
PHP function
<?php
function checkname(){ <--- What do I pass in the function???
$locations = $_POST['location'];
echo $locations;
}
?>
If I do this the "simple way" by just calling the file and do something like
$locations = $_POST['location'];
echo $locations;
I get the return that I need but it will be wrong to just have a small file for all the ajax calls that I need to create.