I'm stuck for quite some time, tried a lot but didn't get the solution.
So, in my app, on hitting the success button I'm showing a success page, and in the same class, I want to post JSON data to a specific URL.
const options = {
hostname: 'localhost',
port: 3500,
path: '/responseSent',
method: 'POST',
headers: {
'Accept': 'application/json',
'Accept-Charset': 'utf-8'
}
};
Below is my post function:
router.post('/', function(req, res, next) {
// Below is the data I need to send to const options (some other URL other than success.ejs)
// Need some code here to send the data (let dataToSend = req.app.locals;) to http://localhost:3500/responseSent
// below is the page I want to show the success animation only (success.ejs locally in project).
res.render('success');
});
I need to render the page at success.ejs, and at the same time need to send the JSON to the other URL. Kindly help.
Thanks in advance :)