I’m not sure what I’m doing wrong but testing out webix jet and trying to pull data from an sql db using php and serving it as JSON to a webix datatable. I can output the JSON to the browser but get nothing in the console.log.
Below is my PHP
<?php
$serverName = "db.server";
$connectionOptions = array(
"Uid" => "db.username",
"PWD" => "dbpassword123",
"Database" => "mydb",
"TrustServerCertificate"=>"Yes"
);
// Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions);
if($conn === false) {
die(print_r(sqlsrv_errors(), true));
}
$sql = "SELECT gc_pk AS id, gc_code, gc_name FROM dbo.GlbCompany";
// Assuming $gc_code is the variable you want to search for
// Prepare the statement
$stmt = sqlsrv_prepare($conn, $sql);
if($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
// Execute the statement
if(sqlsrv_execute($stmt) === false) {
die(print_r(sqlsrv_errors(), true));
}
$data = array();
while($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
$data[] = array('id'=>$row['id'],'code'=>$row['gc_code'],'desc'=>$row['gc_name']);
}
header('Content-Type: application/json;');
echo json_encode($data);
which outputs to my browser the following JSON
[
{
"id": "1FCE8237-E197-41B5-A124-726C00633B46",
"code": "DEM1",
"desc": "Demo Company 1"
},
{
"id": "A789A786-EDE3-458A-BB63-B7BFE1121053",
"code": "DEM2",
"desc": "Demo Company 2"
},
{
"id": "03052ED3-2C64-49AC-97D8-C6079D5015B5",
"code": "DEM3",
"desc": "Demo Company 3"
}
]
Everything is cool there and valid, but when I try to call it with Webix jet
webix.ajax.get("../sources/modules/ajax/get_company.php, function(text, data) {
console.log(data);
});
The below is what console log shows
If I change console.log to display the text I get
So I know I’m calling the file and if I just copy the json and load it as static data it works. I just need to load it from the database.
’
Note: I’m using xampp and vscode on a local machine. I can render webix jet just fine