gpt4 book ai didi

javascript - 如何使用 Codeigniter 从 Ajax Jquery 中的 Controller 获取多个参数?

转载 作者:行者123 更新时间:2023-11-28 06:05:05 28 4
gpt4 key购买 nike

我正在从特定 ID 的文件夹中获取图像列表。现在我正在获取文件名,但我还想获取上传路径。

如何在一个函数中获取两种数据。

Jquery 代码:

listFilesOnServer(project_id);

function listFilesOnServer (project_id) {
var items = [];
uploadURI = uploadURI+'/'+project_id;
console.log(project_id+'--KAL--'+uploadURI);
$.getJSON(uploadURI ,function(data,path) {
console.log(data);
$('div #list-group').html("").html(items.join(""));
});
}

Controller 代码:

function listFiles() {
$this->load->helper('file');
$project_id = $this->uri->segment(3);
$builders_id = $this->admin_model->getBuilderID($project_id);
$UPLD_PATH = $this->admin_model->builder_UPLD_PATH($builders_id);
$upload_path = "./application/assets/images/" . $UPLD_PATH;
$files = get_filenames($upload_path);
echo json_encode($files);
}

最佳答案

您应该修改 Controller 操作,使其返回 json_encode(array('files'=>$yourFiles, 'filePath'=>$yourFilePath) );,如下所示:

function listFiles() {
$this->load->helper('file');
$project_id = $this->uri->segment(3);
$builders_id = $this->admin_model->getBuilderID($project_id);
$UPLD_PATH = $this->admin_model->builder_UPLD_PATH($builders_id);
$upload_path = "./application/assets/images/" . $UPLD_PATH;
$files = get_filenames($upload_path);
echo json_encode(array('files'=>$files, 'uploadPath'=>$upload_path) );
exit();
}

然后修改 jquery 代码来处理 json 响应并提取响应,如下所示:

listFilesOnServer(project_id);

function listFilesOnServer (project_id) {
var items = [];
uploadURI = uploadURI+'/'+project_id;
console.log(project_id+'--KAL--'+uploadURI);
$.getJSON(uploadURI ,function(data,path) {
//Your upload path
console.info("UPLOAD PATH: "+data.uploadPath);
//Your files
console.log(data.files);
//Your processing logic goes here
$('div #list-group').html("").html(items.join(""));
});
}

关于javascript - 如何使用 Codeigniter 从 Ajax Jquery 中的 Controller 获取多个参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36938871/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com