Good morning, it's my first time working with ajax and I would like to know how I can make a variable in JS take values from the database
This is my code in PHP to make the call of the data of the database
<?php
$host = "localhost";
$user = "root";
$pass = "pass";
$databaseName = "bd";
$link=mysqli_connect($host, $user, $pass, $databaseName);
if (mysqli_connect_errno())
echo "Failed to connect to MySQL: " . mysqli_connect_error();
$results=array();
$query="SELECT * FROM tasas";
$show=mysqli_query($link,$query) or die ("Error");
while($row=mysqli_fetch_array($show)){
$results[] = $row['valor'];
}
return $results[];
?>
Now I want the stored data to be able to replace the values that are here so that they take the values of the database
if (pickup == 0){
tasaP = 10;
descP = "Casa u oficina";
}
if (pickup == 1){
tasaP = 0;
descP = "Centro de acopio";
}
else if (pickup == 2){
tasaP = 5;
descP = "Aliado 1";
}
else if (pickup == 3){
tasaP = 6;
descP = "Aliado 2";
}
if (delivery == 0){
tasaD = 5;
descD = "Casa u oficina";
}
else if (delivery == 1){
tasaD = 10;
descD = "Centro de acopio";
}
else{
tasaD = 0;
}
if (insurance == 0){
tasaI = 10;
descI = "Básico";
}
else if (insurance == 1){
tasaI = 25
descI = "Premium";
}
else{
tasaI = 0;
}
if (type == 0){
tasaC = 0;
descC = "Paquete";
}
else{
tasaC = 10;
descC = "Documento";
}
I have read that it is done with Ajax but I can not understand how to grasp the values and replace the static values that I have in my js
If it is possible for someone to explain me in detail I would appreciate it