How Should I store the output of PHP file in a JS variable. I know JS is UI side and PHP is server Side. If there is any other way i can achieve this, will be a good help. And I am new to JS and HTML.
The PHP files get data from mariadb database. which i eventually want to send it to JS so that It can print the (location)value as well in the UI.
What should i type in var slocation
I have .$get , .$post but didnt work
My PHP file looks like this.
<?php
$servername = "localhost";
$username = "trafitek";
$password = "trafitek123";
$db = "ecb_demo";
parse_str($_SERVER['QUERY_STRING']);
$conn = new mysqli($servername, $username, $password, $db);
if($conn->connect_error){
die("connection failed: " .$conn->connect_error);
}
if (isset($_GET['id'])){
$sql = "SELECT * FROM ecb_config WHERE ecb_no='$id'";
$result = $conn->query($sql);
if ($result->num_rows > 0){
while($row = $result->fetch_assoc()){
echo $row['Chainage'];
}
}
else {
echo "";
}
}
?>
The Portion of JS where i want this to work is as follows
var sRemoteNumber = (oSipSessionCall.getRemoteFriendlyName() || 'unknown');
var slocation = $.get( "https://192.168.2.160/CMTSourceCode/getlocation.php?id="+sRemoteNumber+"" );
txtCallStatus.innerHTML = "<i>Incomings call from [<b>" + sRemoteNumber + "</b> <b>"+ slocation +"</b>]</i>";```