Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 节点可以';找不到模块-Express.js_Javascript_Node.js_Express - Fatal编程技术网

Javascript 节点可以';找不到模块-Express.js

Javascript 节点可以';找不到模块-Express.js,javascript,node.js,express,Javascript,Node.js,Express,我有ASP.NET背景。我试图在ASP.NET中使用MVC逻辑来理解Node.js的“路由”逻辑。例如,在我的global.js中,有一个对/users/userlist的AJAX调用(我不知道它是什么,它是MVC中的控制器)。我正试图使用以下代码访问该控制器,但我得到以下信息: 获取404(未找到) 我该怎么做才能摆脱这个?谢谢 这是app.js(完整): 这是users.js(完整): 这是global.js: $.getJSON( '/users/userlist', function(

我有ASP.NET背景。我试图在ASP.NET中使用MVC逻辑来理解Node.js的“路由”逻辑。例如,在我的global.js中,有一个对/users/userlist的AJAX调用(我不知道它是什么,它是MVC中的控制器)。我正试图使用以下代码访问该控制器,但我得到以下信息:

获取404(未找到)

我该怎么做才能摆脱这个?谢谢

这是app.js(完整):

这是users.js(完整):

这是global.js:

$.getJSON( '/users/userlist', function( data ) {

    // For each item in our JSON, add a table row and cells to the content string
    $.each(data, function(){
        tableContent += '<tr>';
        tableContent += '<td><a href="#" class="linkshowuser" rel="' + this.username + '">' + this.username + '</a></td>';
        tableContent += '</tr>';
    });

    // Inject the whole content string into our existing HTML table
    $('#userList table tbody').html(tableContent);
});
当我运行此代码时,我得到以下结果:

获取404(未找到)


在下面的代码行中包含所有代码i app.js

var express = require('express');
var app = express();
// other code below

得到什么?在“当我运行这个代码时,我得到了这样一句话:”什么都没有;)我做了一个编辑:>Get404(未找到)尝试转到localhost:3000/userlist@JayGould它给出了404,我认为
app.use('/',index)可能有点过于贪婪,因为它可能匹配所有路由。js中发生了什么?我们可能正在查看代码的一个缩短版本。这必须已经在文件中,否则服务器代码甚至不会运行,因为对
express()
express.static()
的引用将抛出。
$.getJSON( '/users/userlist', function( data ) {

    // For each item in our JSON, add a table row and cells to the content string
    $.each(data, function(){
        tableContent += '<tr>';
        tableContent += '<td><a href="#" class="linkshowuser" rel="' + this.username + '">' + this.username + '</a></td>';
        tableContent += '</tr>';
    });

    // Inject the whole content string into our existing HTML table
    $('#userList table tbody').html(tableContent);
});
var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

module.exports = router;
var express = require('express');
var app = express();
// other code below