我想从我的节点应用程序访问另一个页面,但这个其他(Branch.html)HTML页面不会为我加载文件。 index.html中所有文件都工作,但是当我切换到使用下面的代码另一个页面,它会停止工作:节点应用程序无法获取/文件名错误
app.get('/branch', function (req, res,html) {
res.sendFile(path.join(__dirname+'/reacted/branch.html'));
});
我的文件夹结构是: Interface-- APP.JS(这就是下面的代码是),那么我所有的页面都在一个名为反应的文件夹中:
app.use(express.static('reacted/public'));
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/reacted/index.html'));
});
以下是我在Branch中的代码。 HTML我在哪里得到错误,我的branches.json找不到。
$.getJSON("/reacted/Branches.json", function (data) {
console.log(data)
$.each(data, function (index, item) {
$('#users-dropdown').append(
$('<option id="branchname" ></option>').val(item).html(item));
});
});
$('#users-dropdown').on('change', function() {
var value = $(this).val();
alert(value);
});
在服务器与branches.json响应没有发现?你可以在路由被调用的时候发布路由对req.params所说的内容吗? – ckross01
它需要我到Branch.html,但branch.html中的下拉是试图调用branches.json在同一个文件夹内,这是没有找到 – Gill