Hi Folks,
I know this is more d3 but does anyone know how to pass a parameter with d3 fetch?
Normally I just use this:
d3.json("dataset.php").then(function(dataSet) {
//dc stuff here
});
But i'm using a (separate) Select to pick an item which I then want to pass to the above.
My latest attempt is:
d3.json("dataset.php", {
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: "selectedItem= selectedItem "
}).then(function(dataSet) {
//dc stuff here
});
dataset.php is :
<?php
$hostname_base = "localhost";
$username_base = "un";
$password_base = "pw";
$database_base = "db";
$connection = mysqli_connect($hostname_base,$username_base,$password_base,$database_base) or die("Error " . mysqli_error($connection));
$selectedItem = $_POST['selectedItem'];
$sql = "SELECT * from myTable WHERE item = '".$selectedItem."' ";
$result = mysqli_query($connection, $sql) or die("Error in: " . mysqli_error($connection));
$emparray = array();
while($row =mysqli_fetch_assoc($result))
{
$emparray[] = $row;
}
echo json_encode($emparray);
mysqli_close($connection);
?>
With ajax I would normally do this:
$.ajax({
url: 'dataset.php',
type: 'POST',
dataType: "json",
data: {
selectedItem: selectedItem
},
Thanks all