2016-03-02 79 views
1

我想从我的节点应用程序访问另一个页面,但这个其他(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); 
}); 
+0

在服务器与branches.json响应没有发现?你可以在路由被调用的时候发布路由对req.params所说的内容吗? – ckross01

+0

它需要我到Branch.html,但branch.html中的下拉是试图调用branches.json在同一个文件夹内,这是没有找到 – Gill

回答

0

它看起来像你的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)); 
}); 
+0

那么我在改变forlder结构方面做什么?它应该如何? – Gill

+0

这真的取决于你的喜好,我喜欢把我所有的html放在一个地方,所有的js放在另一个地方,但它可以保持原样。 除非这是造成问题,是吗? –

+0

它看起来像需要在公共文件夹中,所以我只需将所有代码粘贴到公共foldeR中? – Gill

相关问题