I have a javascript that, with Ajax, gets an array from PHP and adds this data to a dropdown. Its all working.
It seems to me using Ajax for this is overkill, is there a more simple way?
javascript:
function ajaxGetCountries(){
var ajaxRequest;
try { // Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
//etc etc
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
allcountries = JSON.parse(ajaxRequest.responseText);
var lst = document.getElementById('countrylst');
for(var i = 0 ; i < allcountries.length ; i++) {
var opt = document.createElement('option');
opt.innerHTML = allcountries[i];
opt.value = allcountries [i];
lst.appendChild(opt);
}
}
}
ajaxRequest.open("GET", "get_countries.php" , true);
ajaxRequest.send(null);
}
Thanks.