0

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>";```
Jayant
  • 1
  • you can try ajax – Vishwa Apr 08 '19 at 09:52
  • 1
    Look in the developer console to "Network" tab. You should see the GET request You sent with Ajax here. Do You see it or not? If not, You could see some error message in "Console" tab. If yes, does the request return correct output? – Roman Hocke Apr 08 '19 at 09:53
  • 1
    $.get does not actually return a value, but a promise. You need a callback function, check out the jQuery documentation: https://api.jquery.com/jquery.get/ – Fitzi Apr 08 '19 at 09:54
  • Hi but, Is my syntax correct of .$get ?? – Jayant Apr 08 '19 at 09:55
  • i hope use full for this https://stackoverflow.com/questions/55489821/get-returns-string-while-fetching-json-file-only-in-mac/55492545#55492545 – rajmobiapp Apr 08 '19 at 09:55
  • 1
    See the documentation for starters: https://api.jquery.com/jQuery.get/#entry-examples – deceze Apr 08 '19 at 09:56

0 Answers0