what I do is use addOption see http://www.texotela.co.uk/code/
jquery/select/>here
$("#albums").addOption(data.albums, false);
my json response looks like this
{"albums":{"13":"Horses","10":"Lambs\/Sheep","12":"Cows","14":"Other
animals"}}
Mean Mike
On Jun 29, 10:13 am, Alexandre Magno wr
Ricardo,
The code it's still heavy, you are appending in each loop, this is not
a good code pratice for perfomance and if you read the reference I
passed, you will see that it's not so relevant. The code extract
states, it can deal with a lot of data and the perfomance should be a
item to conside
For adding a handful of options in a select performance is almost
irrelevant, it's more than fast enough. You can improve code
readability and performance (a bit) using the Option constructor:
$.post('/path/to/json.php', {params: 'xxx'}, function(data){
var $select = $('#mySelectBox');
$.
Hello,
Yeah, thats right, the code works but it's too heavy
You should concatenate one string with all option and then make a
append. A append inside the loop would break the perfomance:
> $.post('/path/to/json.php', {params: 'go here, if you need them'},
> function(data){
> // "data" conta
Well, lets assume you're getting the JSON you described from the
following ajax call:
$.post('/path/to/json.php', {params: 'go here, if you need them'},
function(data){
// "data" contains that JSON object you described
// Also, I'm assuming your select box looks something like this:
//
5 matches
Mail list logo