我在Node.js中编写了一个代码,用于前端的后端和HTML代码。 Node.js代码传递的值不会打印在html网页上。
Node.js代码是:
var express = require('express');
var app = express();
var fs = require('fs');
var googlePlaySearch = require('google-play-search');
var templateData = "";
var path = require ('path');
app.use(express.static(path.join(__dirname + '.../public')));
app.use(express.static(__dirname + '/public'));
app.set('views', __dirname + '/public/views');
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.set('views', __dirname+'/app');
app.set('view engine', 'dot');
app.use('/css',express.static(__dirname+'/public/css'));
app.use('/img',express.static(__dirname+'/public/img'));
app.use('/js',express.static(__dirname+'/public/js'));
var templateData1 = "";
app.get('/index.htm', function (req, res) {
res.sendFile( __dirname + "/" + "index.html" );
});
app.get('/process_get', function (req, res) {
first_name:req.query.first_name
googlePlaySearch.fetch(req.query.first_name, function(err, response) {
console.log(response.categories);
templateData = response.categories ;
});
var thisObject = {templateData1 : templateData}
res.render(__dirname + "/" + "out.html", thisObject);
});
var server = app.listen(8080, function () {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port)
})
index.html
源代码为:
<!DOCTYPE html>
<html ng-app>
<head>
<title>yo</title>
</head>
<body>
<h1><marquee style="color:yellow">this is a page to find app details..</marquee></h1>
<center>
<table>
<tr>
<form id="f1" action="/process_get" method="GET">
<h3 style="color:red">Package Name</h3>:<br>
<input type="text" name="first_name"><br>
<br>
<input type="submit" value="Submit" style="font-size: 20px">
</form>
</tr>
</table>
</center>
</body>
</html>
out.html
(模板)代码是:
<!DOCTYPE html>
<html ng-app>
<head>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body>
<center>
<form id="f1" method="POST">
<table>
<tr style="border: 1px solid black">
<td style="border: 1px solid black">
<h1>: {{thisObject.categories}}! </h1>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
输出正在打印": !"
,而不是这些符号之间的值。
提前谢谢。