I am having an issue with an ajax function populating a list box with null options. I am fairly new to this and must be overlooking something. The DB connection is done through Sugarcrm and works, as I am using it for an auto complete function as well. I just can't seem to get the options to populate anything besides empty.
index.php
<script>
$(document).ready(function(){
$.ajax({
url: 'search.php',
type: 'json',
success:function(response){
var len = response.length;
$("#sel1").empty();
for( var i = 0; i<len; i++){
$("#sel1").append("<option value='"+name+"'></option>");
}
}
});
});
</script>
<select id="sel1" multiple size="6">
<option value="0">- Select -</option>
</select>
search.php
<?php
global $db;
$rolelistQry = "SELECT distinct name from acl_roles";
$rolelistData = $db->query($rolelistQry);
$name_array = array();
while( $row = $rolelistData->fetch_assoc()){
$name = $row['name'];
$name_array[] = array("name" => $name);
}
echo json_encode($name_array);
?>