Reputation: 1
although I found similar questions the solutions mentioned there wont seem to work for me.
What I'm trying to do:
How far I've come:
My fetch_devices php script echoes:
["test1","test2","test3"]
function FetchDevices(){
alert("Fetching");
$.ajax({
url: 'php/sql/fetch_devices.php',
success: function(devices) {
var elements = Object.keys(devices).length;
var select = document.getElementById("devices");
var option = document.createElement("option");
var i = 0;
while(i < elements)
{
option.text= devices[i];
option.value= devices[i];
select.appendChild(option);
i++;
}
},
cache: false
});
}
But in the end I only see the last option "test3".....
Why is that happening?
Thanks in advance!
Best Regards,
Upvotes: 0
Views: 111