0

I am trying to access my database from d3 module using PHP file that is pulling my database into a JSON. So far the PHP alone works but I have some trouble when I am calling it inside my .html. Cross-origin request flag is raised but I do not know how to avoid it.

<!DOCTYPE html>
<meta charset="utf-8">
<head>
<style>

body {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  width: 960px;
  height: 500px;
  position: relative;
}


</style>
</head>
<body>

</body>

<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
        d3.json("getdata.php", function(data){
        console.log(data[0]);

});

</script>

PHP

<?php

$db = new PDO('sqlite:../../database/LSTM.sqlite');

$result = $db->query('SELECT * FROM metrics');

$datapie = array();

$result->setFetchMode(PDO::FETCH_ASSOC);

while ($row = $result->fetch()) {

    extract($row);

    $datapie[] = array($name,$epoch, $loss,$accuracy,$val_loss,$val_accuracy);
}
$data = json_encode($datapie);
echo $data;

?>
Boat
  • 509
  • 3
  • 8
  • 21

0 Answers0