I am trying to generate a pdf report from my angular app connecting to jsreport. My client app is doing a POST call by passing a sample data to the report server in this way.
$http.post('http://localhost:5488/api/report', {
'template': {
'shortid': 'SypJSv75e',
"data": {"name": "John Doe"}
}
})
.success(function (response) {
console.log(response)
});
As you see in the above code that I am passing {"name": "John Doe"} to the report server.
On the report server, this is the code that I have in the custom scripts section.
function beforeRender(req, res, done) {
req.data.generatedOn = new Date();
done();
}
How do I receive the data in the jsreport that is being passed from client app?
The data
property should not be inside the template
and your request should look like this
$http.post('http://localhost:5488/api/report', {
template: { shortid: 'SypJSv75e' },
data: { name: "John Doe"}
})
.success(function (response) {
console.log(response)
});
Then you can reach "John Doe" inside template content using {{name}}
or in custom script as
function beforeRender(req, res, done) {
//prints into debug John Doe
console.log(req.data.name)
done();
}
You can later consider using jsreport browser javascript client to invoke rendering calls.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.