Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I need to know how to populate a dropdown using the JSON object.. Im using php to send json to the client.. client catches the json data using ajax. i use below code to check what i exactly receive from the server.

  var test = xmlhttp.responseText;
  alert(test);

the result was showing me.. as below...

   {"2":"pricelist.xml","3":"camera.xml", "4":"cd.xml","5":"data.xml"}

what i exactly do is.. i have set of xml files on the server im reading those filenames using php and i convert it to json object using json_encode and then i send that ot the client to populate the dropdownlist using the json data which i send from server. I have no issue in receiving the json data in client side as i tested above. i need to know how do i populate the data using above json data

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
236 views
Welcome To Ask or Share your Answers For Others

1 Answer

Your HTML

<select id="myselect">
</select>

The javascript(Using jQuery)

var json={} // Populate this json object
$.each(json, function(key, value){
    $('#myselect').append("<option value='"+key+"'>"+value+"</option>");
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...