-2
내 node.js 서버에서 json 응답을 받고 웹 페이지에 응답을 표시하는 방법을 알고 싶습니다.내 node.js 서버에서 Json 응답을 얻고 Web (ejs) 페이지에 표시하는 방법
다음을 사용할 수 있습니다app.engine('.html', require('ejs').__express);
:
아래
var request = require("request"),
username = req.body.username,
password = req.body.password,
url = "https://api.ecoachsolutions.com/main.php?ecoachsignin=1&server=remote&user="+username+"&pass="+password;
console.log("url is "+url);
request.get(
{
url : url
},
function (error, response, body) {
// Do more stuff with 'body' here
if (!error && response.statusCode == 200) {
var json_body = JSON.parse(body);
console.log(json_body);
var msg = json_body.profile.user;//this is the message i want to show on my web page(msg)
console.log(msg); // get json response
}
}
);