How can I call the loadlist
function correctly when I have this JSON data?
I am calling like this but it’s not working:
loadlist($('select#selName').get(0), 'pull.php','data.name')
Here is my JSON data:
{
data: [
{
id: "e0b0d8sc5ffd82e",
name: "John",
}
]
}
the function
function loadlist(selobj,url,nameattr) {
$(selobj).empty();
$.getJSON(url,{},function(data)
{
$(selobj).append(
$('<option>Select</option>')
.val('null')
);
$.each(data, function(i,obj)
{
$(selobj).append(
$('<option></option>')
.val(obj[nameattr])
.html(obj[nameattr]));
});
});
}