【发布时间】:2018-02-19 21:12:12
【问题描述】:
$('#lang_choice1').each(function () {
var lang = $(this).val();
$('#lang_files').empty();
$.ajax({
type: "POST",
url: '<?= site_url('translation/language/getDirContents') ?>',
data: {"lang":lang},
dataType:"json",
success: function (data) {
$.each(data,function(id,dir) //here we're doing a foreach loop round each directory with id as the key and directory as the value
{
var opt = $('<option />'); // here we're creating a new select option with for each directory
opt.val(dir);
opt.text(dir.substr(dir.lastIndexOf("\\")+1));
$('#lang_files').append(opt); //here we will append these new select options to a dropdown with the id
});
$("#lang_files").val($("#lang_files option:first").val());
}
});
return false;
});
opt.text(dir.substr(dir.lastIndexOf("\\")+1)); 的使用在 UNIX 系统中引起了问题。但在 Windows 中它可以正常工作。在 UNIX 中它需要是“/” 我怎样才能使它兼容在基于 windows 和 unix 的系统中使用?
【问题讨论】:
-
几乎是stackoverflow.com/questions/14304935/…的副本。那里的答案应该只需稍作修改即可获取文件而不是目录。
标签: javascript jquery ajax