Hi I'm having trouble with an array I get via ajax post. My return on success looks like this:
["OptimiseWeb","Photos","Portal","Projects","Public"]
My problem is that when I do an alert(this) foreach item in the array instead of getting the directory ie. Photos. It's treating it as a string and is looping through each character.
Here is my code:
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>filesystem/get_dropbox_directories",
data: dataString,
dataType: JSON,
success: function(arr)
{
alert(arr);
$.each(arr, function() {
alert(this);
var opt = $('<option />');
opt.val(this);
opt.text(this);
$('#dropbox-directories').append(opt);
});
$('.drop-account-indicator').css('display', 'none');
}
});
Can anyone see where I'm going wrong? Here is my PHP if it helps?
$data = array();
foreach($contents as $sub){
if($sub->is_dir){
$data[] = str_replace('\/', '', $sub->path);
}
}
header('Content-type: application/json');
echo json_encode($data);