I have a HTML page through which I need to pass two variables through post method to a PHP page which accept those two variables and call an API to fetch the result from those two variables. Now, my requirement is to get the API result back to first page. I am not able to get it.
From index.html, I am calling another page with -
$.ajax({
url: "data.php",
type: 'POST',
data: {
difficulty: term,
cr : country
},
success: function (res) {
console.log(res);
}
In data.php, I am taking parameters through POST method and calling API,
$(document).ready(function(){
var data;
$.ajax({
url: "https://key***.co*/api?key="+api_key,
dataType: "json",
data: {
difficulty: <?php echo $diff; ?>,
cr : <?php echo $cr; ?>
},
success: function (res) {
data = difficulty;
}
});
}
Here the api_key is defined above. How to fetch the data back to index.html?