I'm pretty new to this. I'm trying the following. I have a select input dropdown in the productionCalculator.php. Whenever it's input changes, I call a js function. This function needs an array out of a php file. I already learned a lot (like I have to use include unlike require f.e.) but I the only "value" I get back is null. When I define a string variable directly in the called php file, it works, but if I access the array in the other php the returned value is null. And I can't call the array php file directly, because echo would write the result on the site. I'm really stuck. Pls help, I thank you so much.
There a 4 files involved:
The selection in the productionCalculator.php
<body>
<img src="https://images.evetech.net/types/1002/bp" id="bpoImage">
<select name="bpoDropdown" id="bpoDrop" onchange="SetBpoImage()">
<?php
foreach ($blueprintDict as $key => $value) { ?>
<option value=<?php echo $key?>><?php echo $key?></option>
<?php
}
?>
</select>
</body>
The js function which is called, when the dropdown changes. This is a .js file
function SetBpoImage()
{
var e = document.getElementById("bpoDrop");
var index = e.selectedIndex;
var req = new XMLHttpRequest();
req.onload = function() {
console.log(this.responseText);
};
req.open("get", "assets/getBlueprintDict.php", true);
req.send();
}
The getBlueprintDict.php
<?php
require("assets/blueprintDict.php");
echo json_encode($blueprintDict);
?>
And the blueprintDict.php I need in the js function.
<?php
$blueprintDict=array(
"Typhoon" => 1,
"Dominix" => 2,
"Erebus" => 3,
"Small Shield Extender I" => 4,
"Survey Scanner I" => 5,
);
?>