I am making a select
that will have some users and when selecting a user will send a request $.post
to get all records related to the selected user. After returning the related records, the jQuery will return the callback
of the $.post
and through the data returned I need to loop to add all the names returned inside the <option></option>
, the problem is who do not know how to do this. The data will be returned in jSON by PHP and jQuery has to catch by the callback and form a loop to put in <option>
.
I know that to add a record to option
I use the code
$('#example').append('<option value="foo" selected="selected">Foo</option>');
But I wanted to know how to loop with the jSON returned by the callback.