Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.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/4/sql-server-2008/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 车把问题_Javascript_Html_Json_Handlebars.js - Fatal编程技术网

Javascript 车把问题

Javascript 车把问题,javascript,html,json,handlebars.js,Javascript,Html,Json,Handlebars.js,我目前正在尝试运行GET操作,但我的代码似乎不起作用。我已经完成了简单的设置,但是当我单击我创建的按钮从我创建的简单.JSON文件请求数据时,我一直得到“检索到0个文档”。有人能帮忙吗?这里是我的代码附在截图。非常感谢您的帮助。多谢各位 车把- <!DOCTYPE html> <html> <head> <title>Get Request</title> </head> <body> <h

我目前正在尝试运行GET操作,但我的代码似乎不起作用。我已经完成了简单的设置,但是当我单击我创建的按钮从我创建的简单.JSON文件请求数据时,我一直得到“检索到0个文档”。有人能帮忙吗?这里是我的代码附在截图。非常感谢您的帮助。多谢各位

车把-

<!DOCTYPE html>
<html>
<head>
    <title>Get Request</title>
</head>
<body>
    <h2>GET Request</h2S>
    <div class="results">
        {{#each data}}
        <p> {{first_name}} {{last_name}} </p>
        {{/each}}
    </div>
</body>
</html>
JSON-

{
    "id": 1,
    "name": {
        "first_name": "Robert",
        "last_name": "Swanson"
    },
    "title": "Some Dude"
}

请将您的代码粘贴到问题上。@HarshanaSerasing这些代码都附加在我问题的链接中,但由于我是新来的,我猜这可能是错误的做法。我将编辑帖子并实际显示代码。请将您的代码粘贴到问题中。@HarshanaSerasing代码都附加在我问题的链接中,但由于我是新来的,我猜这可能是错误的做法。我将编辑文章并实际显示代码。
    const express  = require("express")
const app = express();
const mongo = require('mongodb').MongoClient;
const assert = require('assert');
const url = 'mongodb://localhost:27017/test';
var bodyParser = require('body-parser'); 
var exphbs  = require('express-handlebars');
 
app.set('view engine', 'handlebars');
app.engine('handlebars', exphbs());

 
app.use(bodyParser.json()); 
app.use(bodyParser.urlencoded({extended: true}));

app.get('/api/user', function(req, res) { 
    mongo.connect(url,{ useUnifiedTopology: true }, function(err, database) {
        const db = database.db('test');
        db.collection('users').find() 
            .toArray(function(err, result) { 
            if (err) { 
                throw err; 
            } 
            console.log(result.length + ' documents retrieved.'); 
            //res.json(result); 
            res.render('user', { data:result, layout:false})
            database.close(); 
        }); 
    }); 
});


app.get('*', function (request, response) {
    response.sendFile('./public/hello.html',{root: __dirname});
});

 
const port = 8900;
app.listen(port);
console.log(`Listening to server: http://localhost:${port}`)
{
    "id": 1,
    "name": {
        "first_name": "Robert",
        "last_name": "Swanson"
    },
    "title": "Some Dude"
}