javascript - Node 应用程序上无法获取/文件名错误

标签 javascript node.js git

我正在尝试从我的 Node 应用程序访问另一个页面,但另一个 (Branch.html)HTML 页面不会为我加载文件。 index.html 中的所有文件都在工作,但是当我使用以下代码切换到另一个页面时,它停止工作:

app.get('/branch', function (req, res,html) {
res.sendFile(path.join(__dirname+'/reacted/branch.html'));
});

我的文件夹结构是: 界面 - APP.JS(这就是下面的代码所在的位置),然后我的所有页面都在一个名为reacted的文件夹中:

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);
});

最佳答案

看起来你的branch.html和branch.json在同一个文件夹中,你应该尝试

$.getJSON("Branches.json", function (data) {
    console.log(data)
    $.each(data, function (index, item) {
    $('#users-dropdown').append(
    $('<option id="branchname" ></option>').val(item).html(item));
});

关于javascript - Node 应用程序上无法获取/文件名错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35750946/

相关文章:

javascript - 使用复选框之类的图像

javascript - create-react-app 落后于最新版本

java - 如何使用 API 通过看板或 Scrum 板列出所有 RALLY 项目?

android - 为什么带有一些配置文件的 _mac 文件夹会自动从 Android Studio 提交到 git

javascript - 在一个文件中要求express并在另一个文件中使用express.static

javascript - 将 Bower 添加到 Gulp/Nodemon/Browsersync/Angular 配置中

javascript - 点击 Android EPSON 热敏打印来自 WebView 的数据?如果找不到打印机?

node.js - Passport.js 登录无法正常工作

git - PowerShell 捕获 Git 输出

git - 如何以相反的顺序git登录?