Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

New to JSON/AJAX here but trying...

PHP page appears to be returning [{"id":"1"},{"id":2}] to my javascript. How would I convert it to something useful like a dropdown in html?

Code:

<script>
function show(str) {
   if (str=="") {
    var ajaxDisplay=xmlhttp.responseText;
    var res=ajaxDisplay.split("#");
    document.getElementById("ajax1").innerHTML=res[1];
     return;
   } 
   if (window.XMLHttpRequest) {
    // code for IE7+, Firefox, Chrome, Opera, Safari
     xmlhttp=new XMLHttpRequest();
   } else { // code for IE6, IE5
     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
   xmlhttp.onreadystatechange=function() {
     if (xmlhttp.readyState==4 && xmlhttp.status==200) {
    var ajaxDisplay=xmlhttp.responseText;
    var res=ajaxDisplay.split("#");
    document.getElementById("ajax1").innerHTML=res[0];
     }
   }
   xmlhttp.open("GET","get.php?q="+str,true);
   xmlhttp.send();
 }
</script>

<div id='ajax1'><b>ID dropdown will be listed here.</b></div>
share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.