gpt4 book ai didi

javascript - 如何在 Dancer 中找到要在 Javascript 中使用的数据文件的路径?

转载 作者:行者123 更新时间:2023-11-29 18:18:54 24 4
gpt4 key购买 nike

我有以下 Javascript 段:

function setLifts() {
var $lifts = [];
$.ajax({
url: 'data/lifts.csv',
contentType: 'text/csv',
async: false,
success: function(text) {
$lifts = text.split(/\n/);
return;
}
});
return $lifts;
}

当我在 Chrome 中加载页面时出现以下错误:GET http://127.0.0.1:3000/data/lifts.c​​sv 404(未找到)

我的 Dancer 应用程序的根目录中有一个数据目录。 csv 文件的正确路径是什么?

谢谢!

最佳答案

您需要定义一个路由处理程序来处理这些问题,并让 Dancer 将文件发送到客户端。查看Dancer doc .

Lets the current route handler send a file to the client. Note that the path of the file must be relative to the public directory unless you use the system_path option (see below).

get '/download/:file' => sub {
return send_file(params->{file});
}

data 目录不包含在标准 Dancer 安装中。出于安全考虑,您应该将数据公开(文档讨论 return send_file('/etc/passwd', system_path => 1);)。

当然,public 中的内容可以在没有路由处理程序的情况下下载。 CSS、JS 和 dispatch.fcgi 供初学者使用。

关于javascript - 如何在 Dancer 中找到要在 Javascript 中使用的数据文件的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20692593/

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