I have a file search.php where I get the input from the form and I create an url. I want the data(url_api) to pass it to an AJAX script, where I can request an json. How can I pass the variable api_url to ajax data ?
Here is my code:
if(filter_input(INPUT_POST, 'submit')){
$area=filter_input(INPUT_POST, 'm', FILTER_SANITIZE_STRING);
// The access url is created with data from the form
$api_url = "http://wwww/api/v1/wwww?";
if ($m !== "") {
$api_url = $api_url . "m=" . $m;
}
$api_url = $api_url . "&api_key=wxaaaaaaaaaaaaaaaaaaaaaaaa";
And the ajax script
$.ajax({
url: 'search.php', //This is the current doc
type: "POST",
dataType:'jsonp', // add json datatype to get json
data: ?,
success: function(data){
console.log(data);
}
});