Answer the question
In order to leave comments, you need to log in
How to replace parameters in ajax request?
I am creating a service in which it is necessary to show the available quantity of goods on my website using the API request, the script looks like this:
<script>
$(document).ready(function(){
let api_link = 'http://simsms.org/priemnik.php?metod=get_count_new&service=opt28&apikey=CRk&country=RU';
$.ajax({
method: 'POST',
url: 'getContentFromUrl.php',
data: {
'ext_url': api_link,
},
success: function(data) {
const new_data = JSON.parse(data);
$('.response').text(new_data.online);
console.log(new_data.online);
},
error:function() {
console.log('Error');
}
});
})
</script>
<?php
$ext_url = $_POST['ext_url'];
echo file_get_contents($ext_url);
?>
Answer the question
In order to leave comments, you need to log in
1. This js is passed into the function
2. On the onChange event for radio broadcasting this function.
3. Inside the function, get the value of the selected radio, and even better, pass the selected option as an argument to the function.
4. Substitute the selected option in the url via concatenation, for example.
Ps. Never!!! Do not publish API keys on such sites and do not push them to github
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question