1
hello personal I am having a problem using nodejs and express, I have never used this language and I do not have much knowledge of it so I will try to be as specific as possible here.
1 I own a webservice Rest that returns me purchase orders with several items but summarizing would be something like this
{ "nrSolicCompra":"94705", "requester":"Jsilva", "items":{"cd material":"259560", " dsMaterial":"Flat head nails", "qtMaterial":"1000" } }
I need to pick up this json and show in front end (which is in EJS nodejs)
currently have the following structure.
a page called index.js where I have the following code that I found on the net:
var express = require('express');
var router = express.Router();
router.get('/teste', function(req, res, next) {
res.render('teste', { variavel: 'passou no teste', solicitacaoCompra: solicitacaoCompra })
});
var http = require('http');
var options = {
host: 'localhost',
port: 8080,
path: '/meuWebService/metodoRetorno',
mothod: 'GET'
};
var solicitacaoCompra;
http.request(options, function(res) {
var body = "";
res.on('data', function(chunk) {
body += chunk;
});
res.on('end', function() {
solicitacaoCompra = JSON.parse(body);
})
}).end();
module.exports = router;
on the test page.ejs I can set this code to print json
<%- JSON.stringify(solicitacaoCompra) %>
and it prints out in string what I need but I’m not able to save it in a variable or make a format in html to stay in a perfect list something like
<table>
<th> numero pedido</th>
<th> solicitante</th>
</table>
the initial table would be just that and when the user clicks on a button called view would appear a modal with the items of that request.
Can you put the JSON that the webservice gives? The example you put on top is poorly formatted and I’m not sure if it’s an array or an object.
– Sergio
of course is this {"nrSolicCompra":"94705","requester":"Jsilva","items":{"cdMaterial":"259560","dsMaterial":"flat head nails","qtMaterial":"1000"}}
– user2913044